From dcf30f8225829735e225aa76d1d03bdc372b1de1 Mon Sep 17 00:00:00 2001
From: Matthew Macy <kmacy@freebsd.org>
Date: Fri, 7 Nov 2014 22:00:41 -0800
Subject: [PATCH] initial stab at compiling COMPAT_MACH

(cherry picked from commit 4b74a6db7b2917232414ae57bd2f0cc0c8b443e9)
Signed-off-by: Scott K <scott@ixsystems.com>
---
 sys/compat/mach/Makefile              |  27 +-
 sys/compat/mach/init_sysent.c         |   5 +
 sys/compat/mach/mach_bootstrap.c      |  17 +-
 sys/compat/mach/mach_bootstrap.h      |   2 +-
 sys/compat/mach/mach_clock.c          |  36 +-
 sys/compat/mach/mach_clock.h          |   2 +-
 sys/compat/mach/mach_errno.c          |   4 +-
 sys/compat/mach/mach_errno.h          |   2 +-
 sys/compat/mach/mach_exception.c      |  95 ++--
 sys/compat/mach/mach_exception.h      |   6 +-
 sys/compat/mach/mach_exec.c           |  36 +-
 sys/compat/mach/mach_exec.h           |  22 +-
 sys/compat/mach/mach_host.c           |  25 +-
 sys/compat/mach/mach_host.h           |   2 +-
 sys/compat/mach/mach_iokit.c          | 111 +++--
 sys/compat/mach/mach_iokit.h          |   2 +-
 sys/compat/mach/mach_message.c        | 176 ++++----
 sys/compat/mach/mach_message.h        |  24 +-
 sys/compat/mach/mach_misc.c           |  74 ++--
 sys/compat/mach/mach_notify.c         |  28 +-
 sys/compat/mach/mach_notify.h         |   8 +-
 sys/compat/mach/mach_port.c           | 124 +++---
 sys/compat/mach/mach_port.h           |  18 +-
 sys/compat/mach/mach_proto.h          | 276 ++++++++++++
 sys/compat/mach/mach_semaphore.c      |  61 ++-
 sys/compat/mach/mach_semaphore.h      |   5 +-
 sys/compat/mach/mach_services.c       |   1 -
 sys/compat/mach/mach_services.h       |   1 -
 sys/compat/mach/mach_services_names.c |   1 -
 sys/compat/mach/mach_syscall.h        | 136 ++----
 sys/compat/mach/mach_syscallargs.h    | 258 -----------
 sys/compat/mach/mach_syscalls.c       | 281 ++++++------
 sys/compat/mach/mach_sysctl.c         |   3 +-
 sys/compat/mach/mach_sysctl.h         |   2 +-
 sys/compat/mach/mach_sysent.c         | 407 ++++++-----------
 sys/compat/mach/mach_task.c           |  99 +++--
 sys/compat/mach/mach_task.h           |   2 +-
 sys/compat/mach/mach_thread.c         |  61 ++-
 sys/compat/mach/mach_thread.h         |  10 +-
 sys/compat/mach/mach_types.h          |   8 +-
 sys/compat/mach/mach_vm.c             | 216 +++++----
 sys/compat/mach/mach_vm.h             |   6 +-
 sys/compat/mach/makemachservices.sh   |  20 +-
 sys/compat/mach/syscalls.c            |   5 +
 sys/compat/mach/syscalls.conf         |  10 +-
 sys/compat/mach/syscalls.master       | 301 ++++++-------
 sys/compat/mach/systrace_args.c       | 804 ++++++++++++++++++++++++++++++++++
 sys/kern/kern_sig.c                   |  26 +-
 sys/sys/signal.h                      |  15 +
 49 files changed, 2223 insertions(+), 1638 deletions(-)
 create mode 100644 sys/compat/mach/init_sysent.c
 create mode 100644 sys/compat/mach/mach_proto.h
 delete mode 100644 sys/compat/mach/mach_syscallargs.h
 create mode 100644 sys/compat/mach/syscalls.c
 create mode 100644 sys/compat/mach/systrace_args.c

diff --git a/sys/compat/mach/Makefile b/sys/compat/mach/Makefile
index 7cc43a8..bbc9ce0 100644
--- a/sys/compat/mach/Makefile
+++ b/sys/compat/mach/Makefile
@@ -1,16 +1,17 @@
-#	$NetBSD: Makefile,v 1.7 2005/12/11 12:20:20 christos Exp $
+# Makefile for syscall tables
+#
+# $FreeBSD$
 
-SYSCALL_DEP=	syscalls.conf syscalls.master ../../kern/makesyscalls.sh
-SYSCALL_OBJS=	mach_sysent.c mach_syscalls.c mach_syscall.h mach_syscallargs.h
-MACH_DEP=	mach_services.master makemachservices.sh
-MACH_OBJ=	mach_services.c mach_services.h mach_services_names.c
+all:
+	@echo "make sysent only"
 
-all:	${SYSCALL_OBJS} ${MACH_OBJ}
+sysent:  mach_sysent.c mach_syscall.h mach_proto.h mach_syscalls.c mach_systrace_args.c
 
-.include <bsd.sys.mk>		# for HOST_SH
-
-${SYSCALL_OBJS}: ${SYSCALL_DEP}
-	${HOST_SH} ../../kern/makesyscalls.sh syscalls.conf syscalls.master
-
-${MACH_OBJ}: ${MACH_DEP}
-	${HOSH_SH} ./makemachservices.sh
+mach_sysent.c mach_syscall.h mach_proto.h mach_syscalls.c mach_systrace_args.c: \
+		../../kern/makesyscalls.sh syscalls.master syscalls.conf
+	-mv -f mach_sysent.c mach_sysent.c.bak
+	-mv -f mach_syscall.h mach_syscall.h.bak
+	-mv -f mach_proto.h mach_proto.h.bak
+	-mv -f mach_syscalls.c mach_syscalls.c.bak
+	-mv -f mach_systrace_args.c mach_systrace_args.c.bak
+	sh ../../kern/makesyscalls.sh syscalls.master syscalls.conf
diff --git a/sys/compat/mach/init_sysent.c b/sys/compat/mach/init_sysent.c
new file mode 100644
index 0000000..68c49ca
--- /dev/null
+++ b/sys/compat/mach/init_sysent.c
@@ -0,0 +1,5 @@
+/*
+ * System call switch table.
+ *
+ * DO NOT EDIT-- this file is automatically generated.
+ * $FreeBSD$
diff --git a/sys/compat/mach/mach_bootstrap.c b/sys/compat/mach/mach_bootstrap.c
index e40c488..5c21f7d 100644
--- a/sys/compat/mach/mach_bootstrap.c
+++ b/sys/compat/mach/mach_bootstrap.c
@@ -1,5 +1,3 @@
-/*	$NetBSD: mach_bootstrap.c,v 1.14 2008/04/28 20:23:44 martin Exp $ */
-
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,14 +28,18 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_bootstrap.c,v 1.14 2008/04/28 20:23:44 martin Exp $");
+__FBSDID("$FreeBSD$");
 
-#include <sys/types.h>
 #include <sys/param.h>
+#include <sys/types.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+
 #include <sys/systm.h>
 #include <sys/signal.h>
 #include <sys/proc.h>
 
+
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
 #include <compat/mach/mach_port.h>
@@ -45,12 +47,15 @@ __KERNEL_RCSID(0, "$NetBSD: mach_bootstrap.c,v 1.14 2008/04/28 20:23:44 martin E
 #include <compat/mach/mach_errno.h>
 #include <compat/mach/mach_services.h>
 
+MALLOC_DEFINE(M_MACH, "mach", "mach compatibility subsystem");
+
+
 int
 mach_bootstrap_look_up(struct mach_trap_args *args)
 {
 	mach_bootstrap_look_up_request_t *req = args->smsg;
 	mach_bootstrap_look_up_reply_t *rep = args->rmsg;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	size_t *msglen = args->rsize;
 	const char service_name[] = "lookup\021"; /* XXX Why */
 	int service_name_len;
@@ -65,7 +70,7 @@ mach_bootstrap_look_up(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 	*msglen = len;
 
-	mr = mach_right_get(NULL, l, MACH_PORT_TYPE_DEAD_NAME, 0);
+	mr = mach_right_get(NULL, td, MACH_PORT_TYPE_DEAD_NAME, 0);
 
 	mach_set_header(rep, req, *msglen);
 
diff --git a/sys/compat/mach/mach_bootstrap.h b/sys/compat/mach/mach_bootstrap.h
index b798ace..536f576 100644
--- a/sys/compat/mach/mach_bootstrap.h
+++ b/sys/compat/mach/mach_bootstrap.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_bootstrap.h,v 1.5 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
diff --git a/sys/compat/mach/mach_clock.c b/sys/compat/mach/mach_clock.c
index d802315..f3c9fef 100644
--- a/sys/compat/mach/mach_clock.c
+++ b/sys/compat/mach/mach_clock.c
@@ -1,6 +1,7 @@
-/*	$NetBSD: mach_clock.c,v 1.19 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
+ * Copyright (c) 2014 Matthew Macy <kmacy@freebsd.org>
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -30,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_clock.c,v 1.19 2008/04/28 20:23:44 martin Exp $");
+__FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -45,10 +46,21 @@ __KERNEL_RCSID(0, "$NetBSD: mach_clock.c,v 1.19 2008/04/28 20:23:44 martin Exp $
 #include <compat/mach/mach_port.h>
 #include <compat/mach/mach_clock.h>
 #include <compat/mach/mach_services.h>
-#include <compat/mach/mach_syscallargs.h>
+#include <compat/mach/mach_proto.h>
+
+#define timespecsub_netbsd(tsp, usp, vsp)                               \
+        do {                                                            \
+                (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;          \
+                (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;       \
+                if ((vsp)->tv_nsec < 0) {                               \
+                        (vsp)->tv_sec--;                                \
+                        (vsp)->tv_nsec += 1000000000L;                  \
+                }                                                       \
+        } while (/* CONSTCOND */ 0)
+
 
 int
-mach_sys_clock_sleep_trap(struct lwp *l, const struct mach_sys_clock_sleep_trap_args *uap, register_t *retval)
+sys_mach_clock_sleep_trap(struct thread *td, struct mach_clock_sleep_trap_args *uap)
 {
 	/* {
 		syscallarg(mach_clock_port_t) clock_name;
@@ -63,12 +75,12 @@ mach_sys_clock_sleep_trap(struct lwp *l, const struct mach_sys_clock_sleep_trap_
 	int error;
 	int ticks;
 
-	mts.tv_sec = SCARG(uap, sleep_sec);
-	mts.tv_nsec = SCARG(uap, sleep_nsec);
+	mts.tv_sec = uap->sleep_sec;
+	mts.tv_nsec = uap->sleep_nsec;
 
-	if (SCARG(uap, sleep_type) == MACH_TIME_ABSOLUTE) {
+	if (uap->sleep_type == MACH_TIME_ABSOLUTE) {
 		nanotime(&cts);
-		timespecsub(&mts, &cts, &tts);
+		timespecsub_netbsd(&mts, &cts, &tts);
 	} else {
 		tts.tv_sec = mts.tv_sec;
 		tts.tv_nsec = mts.tv_nsec;
@@ -79,11 +91,11 @@ mach_sys_clock_sleep_trap(struct lwp *l, const struct mach_sys_clock_sleep_trap_
 
 	tsleep(&dontcare, PZERO|PCATCH, "sleep", ticks);
 
-	if (SCARG(uap, wakeup_time) != NULL) {
+	if (uap->wakeup_time != NULL) {
 		nanotime(&cts);
 		mcts.tv_sec = cts.tv_sec;
 		mcts.tv_nsec = cts.tv_nsec;
-		error = copyout(&mcts, SCARG(uap, wakeup_time), sizeof(mcts));
+		error = copyout(&mcts, uap->wakeup_time, sizeof(mcts));
 		if (error != 0)
 			return error;
 	}
@@ -92,7 +104,7 @@ mach_sys_clock_sleep_trap(struct lwp *l, const struct mach_sys_clock_sleep_trap_
 }
 
 int
-mach_sys_timebase_info(struct lwp *l, const struct mach_sys_timebase_info_args *uap, register_t *retval)
+sys_mach_timebase_info(struct thread *td, struct mach_timebase_info_args *uap)
 {
 	/* {
 		syscallarg(mach_timebase_info_t) info;
@@ -104,7 +116,7 @@ mach_sys_timebase_info(struct lwp *l, const struct mach_sys_timebase_info_args *
 	info.numer = 4000000000UL;
 	info.denom = 75189611UL;
 
-	if ((error = copyout(&info, (void *)SCARG(uap, info),
+	if ((error = copyout(&info, (void *)uap->info,
 	    sizeof(info))) != 0)
 		return error;
 
diff --git a/sys/compat/mach/mach_clock.h b/sys/compat/mach/mach_clock.h
index ea3584e..8347837 100644
--- a/sys/compat/mach/mach_clock.h
+++ b/sys/compat/mach/mach_clock.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_clock.h,v 1.8 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
diff --git a/sys/compat/mach/mach_errno.c b/sys/compat/mach/mach_errno.c
index 7e59e98..12919f65 100644
--- a/sys/compat/mach/mach_errno.c
+++ b/sys/compat/mach/mach_errno.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_errno.c,v 1.18 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,11 +30,9 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_errno.c,v 1.18 2008/04/28 20:23:44 martin Exp $");
 
 #include <sys/types.h>
 #include <sys/systm.h>
-#include <sys/null.h>
 #include <sys/queue.h>
 #include <sys/errno.h>
 
diff --git a/sys/compat/mach/mach_errno.h b/sys/compat/mach/mach_errno.h
index 8a45e5c..d9a54dc 100644
--- a/sys/compat/mach/mach_errno.h
+++ b/sys/compat/mach/mach_errno.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_errno.h,v 1.9 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
diff --git a/sys/compat/mach/mach_exception.c b/sys/compat/mach/mach_exception.c
index 907e122..ffda2ef 100644
--- a/sys/compat/mach/mach_exception.c
+++ b/sys/compat/mach/mach_exception.c
@@ -1,5 +1,3 @@
-/*	$NetBSD: mach_exception.c,v 1.14 2009/03/14 21:04:18 dsl Exp $ */
-
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,20 +28,15 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_exception.c,v 1.14 2009/03/14 21:04:18 dsl Exp $");
-
-#include "opt_compat_darwin.h"
+__FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/signal.h>
+#include <sys/systm.h>
 #include <sys/proc.h>
 #include <sys/malloc.h>
 
-#ifdef COMPAT_DARWIN
-#include <compat/darwin/darwin_exec.h>
-#endif
-
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_exec.h>
 #include <compat/mach/mach_errno.h>
@@ -68,23 +61,23 @@ static void mach_siginfo_to_exception(const struct ksiginfo *, int *);
  * mach_trapinfo1 and handle signals if it gets a non zero return value.
  */
 void
-mach_trapsignal(struct lwp *l, struct ksiginfo *ksi)
+mach_trapsignal(struct thread *td, struct ksiginfo *ksi)
 {
-	if (mach_trapsignal1(l, ksi) != 0)
-		trapsignal(l, ksi);
+	if (mach_trapsignal1(td, ksi) != 0)
+		trapsignal(td, ksi);
 	return;
 }
 
 int
-mach_trapsignal1(struct lwp *l, struct ksiginfo *ksi)
+mach_trapsignal1(struct thread *td, struct ksiginfo *ksi)
 {
-	struct proc *p = l->l_proc;
+	struct proc *p = td->td_proc;
 	struct mach_emuldata *med;
 	int exc_no;
 	int code[2];
 
 	/* Don't inhinbit non maskable signals */
-	if (sigprop[ksi->ksi_signo] & SA_CANTMASK)
+	if (sigprop(ksi->ksi_signo) & SA_CANTMASK)
 		return EINVAL;
 
 	med = (struct mach_emuldata *)p->p_emuldata;
@@ -110,12 +103,12 @@ mach_trapsignal1(struct lwp *l, struct ksiginfo *ksi)
 
 	mach_siginfo_to_exception(ksi, code);
 
-	return mach_exception(l, exc_no, code);
+	return mach_exception(td, exc_no, code);
 }
 
 int
-mach_exception(struct lwp *exc_l, int exc, int *code)
-	/* exc_l:	 currently running lwp */
+mach_exception(struct thread *exc_td, int exc, int *code)
+	/* exc_td:	 currently running thread */
 {
 	int behavior, flavor;
 	mach_msg_header_t *msgh;
@@ -125,7 +118,7 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 	struct mach_lwp_emuldata *exc_mle;
 	struct mach_emuldata *catcher_med;
 	struct mach_right *kernel_mr;
-	struct lwp *catcher_l;	/* The lwp catching the exception */
+	struct thread *catcher_td;	/* The lwp catching the exception */
 	struct mach_right *exc_task;
 	struct mach_right *exc_thread;
 	struct mach_port *exc_port;
@@ -133,14 +126,14 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 	int error = 0;
 
 #ifdef DIAGNOSTIC
-	if (exc_l == NULL) {
-		printf("mach_exception: exc_l = %p\n", exc_l);
+	if (exc_td == NULL) {
+		printf("mach_exception: exc_td = %p\n", exc_td);
 		return ESRCH;
 	}
 #endif
 #ifdef DEBUG_MACH
 	printf("mach_exception: %d.%d, exc %d, code (%d, %d)\n",
-	    exc_l->l_proc->p_pid, exc_l->l_lid, exc, code[0], code[1]);
+	    exc_td->td_proc->p_pid, exc_td->td_lid, exc, code[0], code[1]);
 #endif
 
 	/*
@@ -148,24 +141,22 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 	 * the process at the time it dies.
 	 */
 	if (mach_exception_hang) {
-		struct proc *p = exc_l->l_proc;
+		struct proc *p = exc_td->td_proc;
 
-		sigminusset(&contsigmask, &exc_l->l_sigpendset->sp_set);
-		lwp_lock(exc_l);
+		sigminusset(&contsigmask, &exc_td->td_sigpendset->sp_set);
+		thread_lock(exc_td);
 		p->p_pptr->p_nstopchild++;
 		p->p_stat = SSTOP;
-		exc_l->l_stat = LSSTOP;
+		exc_td->td_stat = LSSTOP;
 		p->p_nrlwps--;
-		KERNEL_UNLOCK_ALL(exc_l, &exc_l->l_biglocks);
-		mi_switch(exc_l);
-		KERNEL_LOCK(exc_l->l_biglocks, exc_l);
+		mi_switch(exc_td);
 	}
 
 	/*
 	 * No exception if there is no exception port or if it has no receiver
 	 */
-	exc_mle = exc_l->l_emuldata;
-	exc_med = exc_l->l_proc->p_emuldata;
+	exc_mle = exc_td->td_emuldata;
+	exc_med = exc_td->td_proc->p_emuldata;
 	if ((exc_port = exc_med->med_exc[exc]) == NULL)
 		return EINVAL;
 
@@ -177,14 +168,14 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 
 #ifdef DEBUG_MACH
 	printf("catcher is %d.%d, state %d\n",
-	    exc_port->mp_recv->mr_lwp->l_proc->p_pid,
+	    exc_port->mp_recv->mr_lwp->td_proc->p_pid,
 	    exc_port->mp_recv->mr_lwp->l_lid,
-	    exc_port->mp_recv->mr_lwp->l_proc->p_stat);
+	    exc_port->mp_recv->mr_lwp->td_proc->p_stat);
 #endif
 	/*
 	 * Don't send exceptions to dying processes
 	 */
-	if (P_ZOMBIE(exc_port->mp_recv->mr_lwp->l_proc)) {
+	if (P_ZOMBIE(exc_port->mp_recv->mr_lwp->td_proc)) {
 		error = ESRCH;
 		goto out;
 	}
@@ -209,8 +200,8 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 	 * a dying parent, a signal is sent instead of the
 	 * notification, this fixes the problem.
 	 */
-	if ((exc_l->l_proc->p_slflag & PSL_TRACED) &&
-	    (exc_l->l_proc->p_pptr->p_sflag & PS_WEXIT)) {
+	if ((exc_td->td_proc->p_slflag & PSL_TRACED) &&
+	    (exc_td->td_proc->p_pptr->p_sflag & PS_WEXIT)) {
 #ifdef DEBUG_MACH
 		printf("mach_exception: deadlock avoided\n");
 #endif
@@ -233,22 +224,22 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 	 * We want the port names in the target process, that is,
 	 * the process with receive right for exc_port.
 	 */
-	catcher_l = exc_port->mp_recv->mr_lwp;
-	catcher_med = catcher_l->l_proc->p_emuldata;
-	exc_mr = mach_right_get(exc_port, catcher_l, MACH_PORT_TYPE_SEND, 0);
+	catcher_td = exc_port->mp_recv->mr_lwp;
+	catcher_med = catcher_td->td_proc->p_emuldata;
+	exc_mr = mach_right_get(exc_port, catcher_td, MACH_PORT_TYPE_SEND, 0);
 	kernel_mr = mach_right_get(catcher_med->med_kernel,
-	    catcher_l, MACH_PORT_TYPE_SEND, 0);
+	    catcher_td, MACH_PORT_TYPE_SEND, 0);
 
 	exc_task = mach_right_get(exc_med->med_kernel,
-	    catcher_l, MACH_PORT_TYPE_SEND, 0);
+	    catcher_td, MACH_PORT_TYPE_SEND, 0);
 	exc_thread = mach_right_get(exc_mle->mle_kernel,
-	    catcher_l, MACH_PORT_TYPE_SEND, 0);
+	    catcher_td, MACH_PORT_TYPE_SEND, 0);
 
 	switch (behavior) {
 	case MACH_EXCEPTION_DEFAULT: {
 		mach_exception_raise_request_t *req;
 
-		req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
+		req = malloc(sizeof(*req), M_MACH, M_WAITOK | M_ZERO);
 		msglen = sizeof(*req);
 		msgh = (mach_msg_header_t *)req;
 
@@ -277,7 +268,7 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 		mach_exception_raise_state_request_t *req;
 		int dc;
 
-		req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
+		req = malloc(sizeof(*req), M_MACH, M_WAITOK | M_ZERO);
 		msglen = sizeof(*req);
 		msgh = (mach_msg_header_t *)req;
 
@@ -293,7 +284,7 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 		req->req_codecount = 2;
 		memcpy(&req->req_code[0], code, sizeof(req->req_code));
 		req->req_flavor = flavor;
-		mach_thread_get_state_machdep(exc_l,
+		mach_thread_get_state_machdep(exc_td,
 		    flavor, req->req_state, &dc);
 
 		msglen = msglen -
@@ -308,7 +299,7 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 		mach_exception_raise_state_identity_request_t *req;
 		int dc;
 
-		req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
+		req = malloc(sizeof(*req), M_MACH, M_WAITOK | M_ZERO);
 		msglen = sizeof(*req);
 		msgh = (mach_msg_header_t *)req;
 
@@ -329,7 +320,7 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 		req->req_codecount = 2;
 		memcpy(&req->req_code[0], code, sizeof(req->req_code));
 		req->req_flavor = flavor;
-		mach_thread_get_state_machdep(exc_l,
+		mach_thread_get_state_machdep(exc_td,
 		    flavor, req->req_state, &dc);
 
 		msglen = msglen -
@@ -362,7 +353,7 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 	 */
 	if (((exc_port = exc_med->med_exc[exc]) == NULL) ||
 	    (exc_port->mp_recv == NULL) ||
-	    (P_ZOMBIE(exc_port->mp_recv->mr_lwp->l_proc))) {
+	    (P_ZOMBIE(exc_port->mp_recv->mr_lwp->td_proc))) {
 		error = ESRCH;
 		goto out;
 	}
@@ -376,12 +367,12 @@ mach_exception(struct lwp *exc_l, int exc, int *code)
 	 */
 #ifdef DEBUG_MACH
 	printf("mach_exception: %d.%d sleep on catcher_med->med_exclock = %p\n",
-	    exc_l->l_proc->p_pid, exc_l->l_lid, &catcher_med->med_exclock);
+	    exc_td->td_proc->p_pid, exc_td->td_lid, &catcher_med->med_exclock);
 #endif
 	error = tsleep(&catcher_med->med_exclock, PZERO, "mach_exc", 0);
 #ifdef DEBUG_MACH
 	printf("mach_exception: %d.%d resumed, error = %d\n",
-	    exc_l->l_proc->p_pid, exc_l->l_lid, error);
+	    exc_td->td_proc->p_pid, exc_td->td_lid, error);
 #endif
 
 	/*
@@ -470,7 +461,7 @@ mach_siginfo_to_exception(const struct ksiginfo *ksi, int *code)
 int
 mach_exception_raise(struct mach_trap_args *args)
 {
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_exception_raise_reply_t *rep;
 	struct mach_emuldata *med;
 
@@ -493,7 +484,7 @@ mach_exception_raise(struct mach_trap_args *args)
 	if (rep->rep_retval != 0)
 		return 0;
 
-	med = l->l_proc->p_emuldata;
+	med = td->td_proc->p_emuldata;
 
 	/*
 	 * Check for unexpected exception acknowledge, whereas
diff --git a/sys/compat/mach/mach_exception.h b/sys/compat/mach/mach_exception.h
index de1e630..6ab6ec9 100644
--- a/sys/compat/mach/mach_exception.h
+++ b/sys/compat/mach/mach_exception.h
@@ -152,9 +152,9 @@ struct mach_exc_info {
 	int mei_behavior;
 };
 
-void mach_trapsignal(struct lwp *, struct ksiginfo *);
-int mach_trapsignal1(struct lwp *, struct ksiginfo *);
-int mach_exception(struct lwp *, int, int *);
+void mach_trapsignal(struct thread *, struct ksiginfo *);
+int mach_trapsignal1(struct thread *, struct ksiginfo *);
+int mach_exception(struct thread *, int, int *);
 
 #endif /* _MACH_EXCEPTION_H_ */
 
diff --git a/sys/compat/mach/mach_exec.c b/sys/compat/mach/mach_exec.c
index ac46629..d2009b9 100644
--- a/sys/compat/mach/mach_exec.c
+++ b/sys/compat/mach/mach_exec.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_exec.c,v 1.74 2010/07/25 11:25:57 jym Exp $	 */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
@@ -30,23 +30,17 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.74 2010/07/25 11:25:57 jym Exp $");
-
-#include "opt_syscall_debug.h"
+__FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
 #include <sys/exec.h>
 #include <sys/queue.h>
-#include <sys/exec_macho.h>
 #include <sys/malloc.h>
 
+#include <sys/sysent.h>
 #include <sys/syscall.h>
-#include <sys/syscallvar.h>
-
-#include <uvm/uvm_extern.h>
-#include <uvm/uvm_param.h>
 
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
@@ -125,7 +119,7 @@ struct emul emul_mach = {
  * emulation, and it probably contains Darwin specific bits.
  */
 int
-exec_mach_copyargs(struct lwp *l, struct exec_package *pack, struct ps_strings *arginfo, char **stackp, void *argp)
+exec_mach_copyargs(struct thread *l, struct exec_package *pack, struct ps_strings *arginfo, char **stackp, void *argp)
 {
 	struct exec_macho_emul_arg *emea;
 	struct exec_macho_object_header *macho_hdr;
@@ -189,7 +183,7 @@ mach_e_proc_exec(struct proc *p, struct exec_package *epp)
 	mach_e_proc_init(p);
 
 	if (p->p_emul != epp->ep_esch->es_emul) {
-		struct lwp *l = LIST_FIRST(&p->p_lwps);
+		struct thread *l = LIST_FIRST(&p->p_lwps);
 		KASSERT(l != NULL);
 		mach_e_lwp_fork(NULL, l);
 	}
@@ -198,14 +192,14 @@ mach_e_proc_exec(struct proc *p, struct exec_package *epp)
 }
 
 void
-mach_e_proc_fork(struct proc *p2, struct lwp *l1, int forkflags)
+mach_e_proc_fork(struct proc *p2, struct thread *l1, int forkflags)
 {
 	mach_e_proc_fork1(p2, l1, 1);
 	return;
 }
 
 void
-mach_e_proc_fork1(struct proc *p2, struct lwp *l1, int allocate)
+mach_e_proc_fork1(struct proc *p2, struct thread *l1, int allocate)
 {
 	struct mach_emuldata *med1;
 	struct mach_emuldata *med2;
@@ -221,7 +215,7 @@ mach_e_proc_fork1(struct proc *p2, struct lwp *l1, int allocate)
 	mach_e_proc_init(p2);
 
 	med1 = p2->p_emuldata;
-	med2 = l1->l_proc->p_emuldata;
+	med2 = td1->td_proc->p_emuldata;
 
 	/*
 	 * Exception ports are inherited between forks,
@@ -267,7 +261,7 @@ mach_e_proc_init(struct proc *p)
 			printf("mach_emuldata allocated for non Mach binary\n");
 #endif
 		p->p_emuldata = malloc(sizeof(struct mach_emuldata),
-		    M_EMULDATA, M_WAITOK | M_ZERO);
+		    M_MACH, M_WAITOK | M_ZERO);
 	}
 
 	med = (struct mach_emuldata *)p->p_emuldata;
@@ -347,7 +341,7 @@ mach_e_proc_exit(struct proc *p)
 {
 	struct mach_emuldata *med;
 	struct mach_right *mr;
-	struct lwp *l;
+	struct thread *l;
 	int i;
 
 	/* There is only one lwp remaining... */
@@ -391,18 +385,18 @@ mach_e_proc_exit(struct proc *p)
 
 	rw_destroy(&med->med_exclock);
 	rw_destroy(&med->med_rightlock);
-	free(med, M_EMULDATA);
+	free(med, M_MACH);
 	p->p_emuldata = NULL;
 
 	return;
 }
 
 void
-mach_e_lwp_fork(struct lwp *l1, struct lwp *l2)
+mach_e_lwp_fork(struct thread *l1, struct thread *l2)
 {
 	struct mach_lwp_emuldata *mle;
 
-	mle = malloc(sizeof(*mle), M_EMULDATA, M_WAITOK);
+	mle = malloc(sizeof(*mle), M_MACH, M_WAITOK);
 	l2->l_emuldata = mle;
 
 	mle->mle_kernel = mach_port_get();
@@ -421,7 +415,7 @@ mach_e_lwp_fork(struct lwp *l1, struct lwp *l2)
 }
 
 void
-mach_e_lwp_exit(struct lwp *l)
+mach_e_lwp_exit(struct thread *l)
 {
 	struct mach_lwp_emuldata *mle;
 
@@ -439,7 +433,7 @@ mach_e_lwp_exit(struct lwp *l)
 	mle->mle_kernel->mp_datatype = MACH_MP_NONE;
 	MACH_PORT_UNREF(mle->mle_kernel);
 
-	free(mle, M_EMULDATA);
+	free(mle, M_MACH);
 	l->l_emuldata = NULL;
 
 	return;
diff --git a/sys/compat/mach/mach_exec.h b/sys/compat/mach/mach_exec.h
index 06a8914..28674f1 100644
--- a/sys/compat/mach/mach_exec.h
+++ b/sys/compat/mach/mach_exec.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_exec.h,v 1.35 2011/03/05 23:51:47 joerg Exp $	 */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -31,8 +31,8 @@
 
 #ifndef	_MACH_EXEC_H_
 #define	_MACH_EXEC_H_
-
-#include <uvm/uvm_extern.h>
+#include <sys/lock.h>
+#include <sys/rwlock.h>
 
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
@@ -44,7 +44,7 @@ struct mach_emuldata {
 	int med_inited;			/* Is this structure initialized? */
 	int med_thpri;			/* Saved priority */
 	LIST_HEAD(med_right, mach_right) med_right;
-	krwlock_t med_rightlock;	/* process right list and lock */
+	struct rwlock med_rightlock;	/* process right list and lock */
 	mach_port_t med_nextright;	/* next unused right */
 
 	struct mach_port *med_bootstrap;/* task bootstrap port */
@@ -54,24 +54,24 @@ struct mach_emuldata {
 
 	int med_dirty_thid;		/* Thread id not yet initialized */
 	int med_suspend;		/* Suspend semaphore */
-	krwlock_t med_exclock;		/* Process exception handler lock */
+	struct rwlock med_exclock;		/* Process exception handler lock */
 };
 
-struct mach_lwp_emuldata {
+struct mach_thread_emuldata {
 	struct mach_port *mle_kernel;	/* Thread's kernel port */
 };
 
 struct ps_strings;
-int exec_mach_copyargs(struct lwp *, struct exec_package *,
+int exec_mach_copyargs(struct thread *, struct exec_package *,
     struct ps_strings *, char **, void *);
 int exec_mach_probe(const char **);
 void mach_e_proc_init(struct proc *);
 void mach_e_proc_exit(struct proc *);
 void mach_e_proc_exec(struct proc *, struct exec_package *);
-void mach_e_proc_fork(struct proc *, struct lwp *, int);
-void mach_e_proc_fork1(struct proc *, struct lwp *, int);
-void mach_e_lwp_fork(struct lwp *, struct lwp *);
-void mach_e_lwp_exit(struct lwp *);
+void mach_e_proc_fork(struct proc *, struct thread *, int);
+void mach_e_proc_fork1(struct proc *, struct thread *, int);
+void mach_e_lwp_fork(struct thread *, struct thread *);
+void mach_e_lwp_exit(struct thread *);
 
 extern struct emul emul_mach;
 
diff --git a/sys/compat/mach/mach_host.c b/sys/compat/mach/mach_host.c
index 767348c..c9b7ffc 100644
--- a/sys/compat/mach/mach_host.c
+++ b/sys/compat/mach/mach_host.c
@@ -1,5 +1,3 @@
-/*	$NetBSD: mach_host.c,v 1.31 2008/04/28 20:23:44 martin Exp $ */
-
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.31 2008/04/28 20:23:44 martin Exp $");
+__FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -40,9 +38,6 @@ __KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.31 2008/04/28 20:23:44 martin Exp $"
 #include <sys/signal.h>
 #include <sys/proc.h>
 
-#include <uvm/uvm_extern.h>
-#include <uvm/uvm_param.h>
-
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_host.h>
 #include <compat/mach/mach_port.h>
@@ -144,10 +139,10 @@ mach_host_get_clock_service(struct mach_trap_args *args)
 	mach_host_get_clock_service_request_t *req = args->smsg;
 	mach_host_get_clock_service_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_right *mr;
 
-	mr = mach_right_get(mach_clock_port, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mach_clock_port, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
@@ -179,10 +174,10 @@ mach_host_get_io_master(struct mach_trap_args *args)
 	mach_host_get_io_master_request_t *req = args->smsg;
 	mach_host_get_io_master_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_right *mr;
 
-	mr = mach_right_get(mach_io_master_port, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mach_io_master_port, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
@@ -198,12 +193,12 @@ mach_processor_set_default(struct mach_trap_args *args)
 	mach_processor_set_default_request_t *req = args->smsg;
 	mach_processor_set_default_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_right *mr;
 	struct mach_port *mp;
 
 	mp = mach_port_get();
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
@@ -219,18 +214,18 @@ mach_host_processor_set_priv(struct mach_trap_args *args)
 	mach_host_processor_set_priv_request_t *req = args->smsg;
 	mach_host_processor_set_priv_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 	struct mach_right *smr;
 	struct mach_port *smp;
 
 	mn = req->req_set.name;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_msg_error(args, EINVAL);
 
 	smp = mach_port_get();
-	smr = mach_right_get(smp, l, MACH_PORT_TYPE_SEND, 0);
+	smr = mach_right_get(smp, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
diff --git a/sys/compat/mach/mach_host.h b/sys/compat/mach/mach_host.h
index ed57c90..abbab10 100644
--- a/sys/compat/mach/mach_host.h
+++ b/sys/compat/mach/mach_host.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_host.h,v 1.17 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
diff --git a/sys/compat/mach/mach_iokit.c b/sys/compat/mach/mach_iokit.c
index 502ea2b..df5ec36 100644
--- a/sys/compat/mach/mach_iokit.c
+++ b/sys/compat/mach/mach_iokit.c
@@ -1,5 +1,3 @@
-/*	$NetBSD: mach_iokit.c,v 1.36 2008/04/28 20:23:44 martin Exp $ */
-
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,9 +27,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "opt_compat_darwin.h"
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_iokit.c,v 1.36 2008/04/28 20:23:44 martin Exp $");
+__FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -87,7 +84,7 @@ mach_io_service_get_matching_services(struct mach_trap_args *args)
 	mach_io_service_get_matching_services_request_t *req = args->smsg;
 	mach_io_service_get_matching_services_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_port *mp;
 	struct mach_right *mr;
 	struct mach_iokit_devclass *mid;
@@ -103,7 +100,7 @@ mach_io_service_get_matching_services(struct mach_trap_args *args)
 
 	mp = mach_port_get();
 	mp->mp_flags |= MACH_MP_INKERNEL;
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	mp->mp_data = NULL;
 	i = 0;
@@ -114,7 +111,7 @@ mach_io_service_get_matching_services(struct mach_trap_args *args)
 
 			size = sizeof(*mdi)
 			    + sizeof(struct mach_device_iterator *);
-			mdi = malloc(size, M_EMULDATA, M_WAITOK);
+			mdi = malloc(size, M_MACH, M_WAITOK);
 			mdi->mdi_devices[0] = mid;
 			mdi->mdi_devices[1] = NULL;
 			mdi->mdi_current = 0;
@@ -141,14 +138,14 @@ mach_io_iterator_next(struct mach_trap_args *args)
 	mach_io_iterator_next_request_t *req = args->smsg;
 	mach_io_iterator_next_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_port *mp;
 	struct mach_right *mr;
 	struct mach_device_iterator *mdi;
 	mach_port_t mn;
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	if (mr->mr_port->mp_datatype != MACH_MP_DEVICE_ITERATOR)
@@ -165,7 +162,7 @@ mach_io_iterator_next(struct mach_trap_args *args)
 	mp->mp_datatype = MACH_MP_IOKIT_DEVCLASS;
 	mp->mp_data = mdi->mdi_devices[mdi->mdi_current++];
 
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
@@ -181,13 +178,13 @@ mach_io_service_open(struct mach_trap_args *args)
 	mach_io_service_open_request_t *req = args->smsg;
 	mach_io_service_open_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_port *mp;
 	struct mach_right *mr;
 	mach_port_t mn;
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	mp = mach_port_get();
@@ -196,7 +193,7 @@ mach_io_service_open(struct mach_trap_args *args)
 		mp->mp_datatype = MACH_MP_IOKIT_DEVCLASS;
 		mp->mp_data = mr->mr_port->mp_data;
 	}
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
@@ -210,7 +207,7 @@ int
 mach_io_connect_method_scalari_scalaro(struct mach_trap_args *args)
 {
 	mach_io_connect_method_scalari_scalaro_request_t *req = args->smsg;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 	struct mach_iokit_devclass *mid;
@@ -231,7 +228,7 @@ mach_io_connect_method_scalari_scalaro(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	if (mr->mr_port->mp_datatype == MACH_MP_IOKIT_DEVCLASS) {
@@ -252,13 +249,13 @@ mach_io_connect_get_service(struct mach_trap_args *args)
 	mach_io_connect_get_service_request_t *req = args->smsg;
 	mach_io_connect_get_service_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_port *mp;
 	struct mach_right *mr;
 	mach_port_t mn;
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	mp = mach_port_get();
@@ -267,7 +264,7 @@ mach_io_connect_get_service(struct mach_trap_args *args)
 		mp->mp_datatype = MACH_MP_IOKIT_DEVCLASS;
 		mp->mp_data = mr->mr_port->mp_data;
 	}
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	/*
 	 * XXX Bump the refcount to workaround an emulation bug
@@ -289,7 +286,7 @@ mach_io_registry_entry_create_iterator(struct mach_trap_args *args)
 	mach_io_registry_entry_create_iterator_request_t *req = args->smsg;
 	mach_io_registry_entry_create_iterator_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_port *mp;
 	mach_port_t mn;
 	struct mach_right *mr;
@@ -310,7 +307,7 @@ mach_io_registry_entry_create_iterator(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 	if (mr->mr_port->mp_datatype != MACH_MP_IOKIT_DEVCLASS)
 		return mach_iokit_error(args, MACH_IOKIT_EINVAL);
@@ -322,7 +319,7 @@ mach_io_registry_entry_create_iterator(struct mach_trap_args *args)
 
 	maxdev = sizeof(mach_iokit_devclasses);
 	size = sizeof(*mdi) + (maxdev * sizeof(struct mach_iokit_devclass *));
-	mdi = malloc(size, M_EMULDATA, M_WAITOK);
+	mdi = malloc(size, M_MACH, M_WAITOK);
 	mp->mp_data = mdi;
 
 	if (req->req_options & MACH_IOKIT_PARENT_ITERATOR)
@@ -344,7 +341,7 @@ mach_io_registry_entry_create_iterator(struct mach_trap_args *args)
 
 	mdi->mdi_current = 0;
 
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 #ifdef DEBUG_MACH
 	printf("io_registry_entry_create_iterator\n");
@@ -394,7 +391,7 @@ mach_io_service_add_interest_notification(struct mach_trap_args *args)
 	mach_io_service_add_interest_notification_request_t *req = args->smsg;
 	mach_io_service_add_interest_notification_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_port *mp;
 	struct mach_right *mr;
 	int end_offset, refcount_offset;
@@ -424,7 +421,7 @@ mach_io_service_add_interest_notification(struct mach_trap_args *args)
 
 	mp = mach_port_get();
 	mp->mp_flags |= MACH_MP_INKERNEL;
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 #ifdef DEBUG_DARWIN
 	uprintf("Unimplemented mach_io_service_add_interest_notification\n");
@@ -442,7 +439,7 @@ mach_io_connect_set_notification_port(struct mach_trap_args *args)
 {
 	mach_io_connect_set_notification_port_request_t *req = args->smsg;
 	mach_io_connect_set_notification_port_reply_t *rep = args->rmsg;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	size_t *msglen = args->rsize;
 	mach_port_t mnn, mn;
 	struct mach_right *mrn;
@@ -453,11 +450,11 @@ mach_io_connect_set_notification_port(struct mach_trap_args *args)
 	printf("mach_io_connect_set_notification_port\n");
 #endif
 	mnn = req->req_port.name;
-	if ((mrn = mach_right_check(mnn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mrn = mach_right_check(mnn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_msg_error(args, EINVAL);
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_msg_error(args, EINVAL);
 
 	if (mr->mr_port->mp_datatype != MACH_MP_IOKIT_DEVCLASS)
@@ -485,7 +482,7 @@ mach_io_registry_get_root_entry(struct mach_trap_args *args)
 	mach_io_registry_get_root_entry_request_t *req = args->smsg;
 	mach_io_registry_get_root_entry_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_port *mp;
 	struct mach_right *mr;
 
@@ -494,7 +491,7 @@ mach_io_registry_get_root_entry(struct mach_trap_args *args)
 	mp->mp_datatype = MACH_MP_IOKIT_DEVCLASS;
 	mp->mp_data = &mach_ioroot_devclass;
 
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
@@ -510,7 +507,7 @@ mach_io_registry_entry_get_child_iterator(struct mach_trap_args *args)
 	mach_io_registry_entry_get_child_iterator_request_t *req = args->smsg;
 	mach_io_registry_entry_get_child_iterator_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_port *mp;
 	struct mach_right *mr;
 	mach_port_t mn;
@@ -529,7 +526,7 @@ mach_io_registry_entry_get_child_iterator(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 	if (mr->mr_port->mp_datatype != MACH_MP_IOKIT_DEVCLASS)
 		return mach_iokit_error(args, MACH_IOKIT_EINVAL);
@@ -541,13 +538,13 @@ mach_io_registry_entry_get_child_iterator(struct mach_trap_args *args)
 
 	maxdev = sizeof(mach_iokit_devclasses);
 	size = sizeof(*mdi) + (maxdev * sizeof(struct mach_iokit_devclass *));
-	mdi = malloc(size, M_EMULDATA, M_WAITOK);
+	mdi = malloc(size, M_MACH, M_WAITOK);
 	mp->mp_data = mdi;
 
 	(void)mach_fill_child_iterator(mdi, maxdev, 0, mid);
 	mdi->mdi_current = 0;
 
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
@@ -563,7 +560,7 @@ mach_io_registry_entry_get_name_in_plane(struct mach_trap_args *args)
 	mach_io_registry_entry_get_name_in_plane_request_t *req = args->smsg;
 	mach_io_registry_entry_get_name_in_plane_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_right *mr;
 	mach_port_t mn;
 	struct mach_iokit_devclass *mid;
@@ -578,7 +575,7 @@ mach_io_registry_entry_get_name_in_plane(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 	if (mr->mr_port->mp_datatype != MACH_MP_IOKIT_DEVCLASS)
 		return mach_iokit_error(args, MACH_IOKIT_EINVAL);
@@ -655,7 +652,7 @@ mach_io_registry_entry_get_properties(struct mach_trap_args *args)
 	mach_io_registry_entry_get_properties_request_t *req = args->smsg;
 	mach_io_registry_entry_get_properties_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	int error;
 	void *uaddr;
 	size_t size;
@@ -664,7 +661,7 @@ mach_io_registry_entry_get_properties(struct mach_trap_args *args)
 	struct mach_iokit_devclass *mid;
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	if (mr->mr_port->mp_datatype != MACH_MP_IOKIT_DEVCLASS)
@@ -679,7 +676,7 @@ mach_io_registry_entry_get_properties(struct mach_trap_args *args)
 	    mid->mid_properties, &uaddr, size, MACH_OOL_TRACE)) != 0) {
 #ifdef DEBUG_MACH
 		printf("pid %d.%d: copyout iokit properties failed\n",
-		    l->l_proc->p_pid, l->l_lid);
+		    td->td_proc->p_pid, td->td_lid);
 #endif
 	}
 
@@ -700,7 +697,7 @@ mach_io_registry_entry_get_property(struct mach_trap_args *args)
 	mach_io_registry_entry_get_property_request_t *req = args->smsg;
 	mach_io_registry_entry_get_property_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	int error;
 	void *uaddr;
 	size_t size;
@@ -720,7 +717,7 @@ mach_io_registry_entry_get_property(struct mach_trap_args *args)
 
 	/* Find the port */
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	/* Find the devclass information */
@@ -746,7 +743,7 @@ mach_io_registry_entry_get_property(struct mach_trap_args *args)
 	    mip->mip_value, &uaddr, size, MACH_OOL_TRACE)) != 0) {
 #ifdef DEBUG_MACH
 		printf("pid %d.%d: copyout iokit property failed\n",
-		    l->l_proc->p_pid, l->l_lid);
+		    td->td_proc->p_pid, td->td_lid);
 #endif
 	}
 
@@ -812,13 +809,13 @@ int
 mach_io_connect_map_memory(struct mach_trap_args *args)
 {
 	mach_io_connect_map_memory_request_t *req = args->smsg;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 	struct mach_iokit_devclass *mid;
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	if (mr->mr_port->mp_datatype == MACH_MP_IOKIT_DEVCLASS) {
@@ -839,13 +836,13 @@ mach_io_iterator_reset(struct mach_trap_args *args)
 	mach_io_iterator_reset_request_t *req = args->smsg;
 	mach_io_iterator_reset_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 	struct mach_device_iterator *mdi;
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	if (mr->mr_port->mp_datatype != MACH_MP_DEVICE_ITERATOR)
@@ -868,7 +865,7 @@ int
 mach_io_connect_method_scalari_structo(struct mach_trap_args *args)
 {
 	mach_io_connect_method_scalari_structo_request_t *req = args->smsg;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 	struct mach_iokit_devclass *mid;
@@ -885,7 +882,7 @@ mach_io_connect_method_scalari_structo(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	if (mr->mr_port->mp_datatype == MACH_MP_IOKIT_DEVCLASS) {
@@ -904,7 +901,7 @@ int
 mach_io_connect_method_structi_structo(struct mach_trap_args *args)
 {
 	mach_io_connect_method_structi_structo_request_t *req = args->smsg;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 	struct mach_iokit_devclass *mid;
@@ -923,7 +920,7 @@ mach_io_connect_method_structi_structo(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	if (mr->mr_port->mp_datatype == MACH_MP_IOKIT_DEVCLASS) {
@@ -1003,7 +1000,7 @@ int
 mach_io_connect_method_scalari_structi(struct mach_trap_args *args)
 {
 	mach_io_connect_method_scalari_structi_request_t *req = args->smsg;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 	struct mach_iokit_devclass *mid;
@@ -1025,7 +1022,7 @@ mach_io_connect_method_scalari_structi(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	if (mr->mr_port->mp_datatype == MACH_MP_IOKIT_DEVCLASS) {
@@ -1046,7 +1043,7 @@ mach_io_registry_entry_from_path(struct mach_trap_args *args)
 	mach_io_registry_entry_from_path_request_t *req = args->smsg;
 	mach_io_registry_entry_from_path_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_port *mp;
 	struct mach_right *mr;
 	struct mach_iokit_devclass *mid;
@@ -1067,7 +1064,7 @@ mach_io_registry_entry_from_path(struct mach_trap_args *args)
 
 	mp = mach_port_get();
 	mp->mp_flags |= MACH_MP_INKERNEL;
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	i = 0;
 	while ((mid = mach_iokit_devclasses[i++]) != NULL) {
@@ -1099,7 +1096,7 @@ mach_io_registry_entry_get_parent_iterator(struct mach_trap_args *args)
 	mach_io_registry_entry_get_parent_iterator_request_t *req = args->smsg;
 	mach_io_registry_entry_get_parent_iterator_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_port *mp;
 	struct mach_right *mr;
 	struct mach_iokit_devclass *mid;
@@ -1123,7 +1120,7 @@ mach_io_registry_entry_get_parent_iterator(struct mach_trap_args *args)
 #endif
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_iokit_error(args, MACH_IOKIT_EPERM);
 
 	if (mr->mr_port->mp_datatype != MACH_MP_IOKIT_DEVCLASS)
@@ -1136,13 +1133,13 @@ mach_io_registry_entry_get_parent_iterator(struct mach_trap_args *args)
 
 	maxdev = sizeof(mach_iokit_devclasses);
 	size = sizeof(*mdi) + (maxdev * sizeof(struct mach_iokit_devclass *));
-	mdi = malloc(size, M_EMULDATA, M_WAITOK);
+	mdi = malloc(size, M_MACH, M_WAITOK);
 	mp->mp_data = mdi;
 
 	(void)mach_fill_parent_iterator(mdi, maxdev, 0, mid);
 	mdi->mdi_current = 0;
 
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
diff --git a/sys/compat/mach/mach_iokit.h b/sys/compat/mach/mach_iokit.h
index 2981964..8308db5 100644
--- a/sys/compat/mach/mach_iokit.h
+++ b/sys/compat/mach/mach_iokit.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_iokit.h,v 1.26 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
diff --git a/sys/compat/mach/mach_message.c b/sys/compat/mach/mach_message.c
index c7e60a7..0b005e4 100644
--- a/sys/compat/mach/mach_message.c
+++ b/sys/compat/mach/mach_message.c
@@ -1,5 +1,3 @@
-/*	$NetBSD: mach_message.c,v 1.59 2009/03/18 16:00:17 cegger Exp $ */
-
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,10 +28,9 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_message.c,v 1.59 2009/03/18 16:00:17 cegger Exp $");
+__FBSDID("$FreeBSD$");
 
 #include "opt_compat_mach.h" /* For COMPAT_MACH in <sys/ktrace.h> */
-#include "opt_compat_darwin.h"
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -46,15 +43,12 @@ __KERNEL_RCSID(0, "$NetBSD: mach_message.c,v 1.59 2009/03/18 16:00:17 cegger Exp
 #include <sys/pool.h>
 #include <sys/ktrace.h>
 
-#include <uvm/uvm_extern.h>
-#include <uvm/uvm_map.h>
-
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
 #include <compat/mach/mach_port.h>
 #include <compat/mach/mach_exec.h>
 #include <compat/mach/mach_clock.h>
-#include <compat/mach/mach_syscallargs.h>
+#include <compat/mach/mach_proto.h>
 
 #ifdef COMPAT_DARWIN
 #include <compat/darwin/darwin_exec.h>
@@ -64,19 +58,19 @@ __KERNEL_RCSID(0, "$NetBSD: mach_message.c,v 1.59 2009/03/18 16:00:17 cegger Exp
 static struct pool mach_message_pool;
 
 static inline
-    int mach_msg_send(struct lwp *, mach_msg_header_t *, int *, size_t);
-static inline int mach_msg_recv(struct lwp *, mach_msg_header_t *,
+    int mach_msg_send(struct thread *, mach_msg_header_t *, int *, size_t);
+static inline int mach_msg_recv(struct thread *, mach_msg_header_t *,
     int, size_t, unsigned int, mach_port_t);
 static inline
-    struct lwp *mach_get_target_task(struct lwp *, struct mach_port *);
+    struct thread *mach_get_target_task(struct thread *, struct mach_port *);
 static inline void mach_drop_rights(struct mach_right *, int);
 static inline
-    void mach_trade_rights(struct lwp *, struct lwp *, mach_port_t *, int);
+    void mach_trade_rights(struct thread *, struct thread *, mach_port_t *, int);
 static inline
-    int mach_trade_rights_complex(struct lwp *, struct mach_message *);
+    int mach_trade_rights_complex(struct thread *, struct mach_message *);
 
 int
-mach_sys_msg_overwrite_trap(struct lwp *l, const struct mach_sys_msg_overwrite_trap_args *uap, register_t *retval)
+mach_sys_msg_overwrite_trap(struct thread *td, const struct mach_sys_msg_overwrite_trap_args *uap)
 {
 	/* {
 		syscallarg(mach_msg_header_t *) msg;
@@ -93,18 +87,18 @@ mach_sys_msg_overwrite_trap(struct lwp *l, const struct mach_sys_msg_overwrite_t
 	mach_msg_header_t *msg;
 	int opt;
 
-	*retval = MACH_MSG_SUCCESS;
-	send_size = SCARG(uap, send_size);
-	recv_size = SCARG(uap, rcv_size);
-	opt = SCARG(uap, option);
+	td->td_retval[0] = MACH_MSG_SUCCESS;
+	send_size = uap->send_size;
+	recv_size = uap->rcv_size;
+	opt = uap->option;
 
 	/* XXX not safe enough: lots of big messages will kill us */
 	if (send_size > MACH_MAX_MSG_LEN) {
-		*retval = MACH_SEND_TOO_LARGE;
+		td->td_retval[0] = MACH_SEND_TOO_LARGE;
 		return 0;
 	}
 	if (recv_size > MACH_MAX_MSG_LEN) {
-		*retval = MACH_RCV_TOO_LARGE;
+		td->td_retval[0] = MACH_RCV_TOO_LARGE;
 		return 0;
 	}
 
@@ -113,25 +107,25 @@ mach_sys_msg_overwrite_trap(struct lwp *l, const struct mach_sys_msg_overwrite_t
 	 * set, we must send, and then receive. If
 	 * send fail, then we skip recieve.
 	 */
-	msg = SCARG(uap, msg);
+	msg = uap->msg;
 	if (opt & MACH_SEND_MSG)
-		*retval = mach_msg_send(l, msg, &opt, send_size);
+		td->td_retval[0] = mach_msg_send(td, msg, &opt, send_size);
 
-	if ((opt & MACH_RCV_MSG) && (*retval == MACH_MSG_SUCCESS)) {
+	if ((opt & MACH_RCV_MSG) && (td->td_retval[0] == MACH_MSG_SUCCESS)) {
 		/*
 		 * Find a buffer for the reply.
 		 */
-		if (SCARG(uap, rcv_msg) != NULL)
-			msg = SCARG(uap, rcv_msg);
-		else if (SCARG(uap, msg) != NULL)
-			msg = SCARG(uap, msg);
+		if (uap->rcv_msg != NULL)
+			msg = uap->rcv_msg;
+		else if (uap->msg != NULL)
+			msg = uap->msg;
 		else {
-			*retval = MACH_RCV_INVALID_DATA;
+			td->td_retval[0] = MACH_RCV_INVALID_DATA;
 			return 0;
 		}
 
-		*retval = mach_msg_recv(l, msg, opt, recv_size,
-		    SCARG(uap, timeout), SCARG(uap, rcv_name));
+		td->td_retval[0] = mach_msg_recv(td, msg, opt, recv_size,
+		    uap->timeout, uap->rcv_name);
 	}
 
 	return 0;
@@ -141,11 +135,11 @@ mach_sys_msg_overwrite_trap(struct lwp *l, const struct mach_sys_msg_overwrite_t
  * Send a Mach message. This returns a Mach message error code.
  */
 static inline int
-mach_msg_send(struct lwp *l, mach_msg_header_t *msg, int *option, size_t send_size)
+mach_msg_send(struct thread *td, mach_msg_header_t *msg, int *option, size_t send_size)
 {
 	struct mach_emuldata *med;
 	struct mach_port *mp;
-	struct proc *p = l->l_proc;
+	struct proc *p = td->td_proc;
 	mach_msg_header_t *sm;
 	struct mach_service *srv;
 	mach_port_t ln;
@@ -165,7 +159,7 @@ mach_msg_send(struct lwp *l, mach_msg_header_t *msg, int *option, size_t send_si
 	 * Allocate memory for the message and its reply,
 	 * and copy the whole message in the kernel.
 	 */
-	sm = malloc(send_size, M_EMULDATA, M_WAITOK);
+	sm = malloc(send_size, M_MACH, M_WAITOK);
 	if ((error = copyin(msg, sm, send_size)) != 0) {
 		ret = MACH_SEND_INVALID_DATA;
 		goto out1;
@@ -180,8 +174,8 @@ mach_msg_send(struct lwp *l, mach_msg_header_t *msg, int *option, size_t send_si
 	ln = sm->msgh_local_port;
 	rn = sm->msgh_remote_port;
 
-	lr = mach_right_check(ln, l, MACH_PORT_TYPE_ALL_RIGHTS);
-	rr = mach_right_check(rn, l, MACH_PORT_TYPE_ALL_RIGHTS);
+	lr = mach_right_check(ln, td, MACH_PORT_TYPE_ALL_RIGHTS);
+	rr = mach_right_check(rn, td, MACH_PORT_TYPE_ALL_RIGHTS);
 	if ((rr == NULL) || (rr->mr_port == NULL)) {
 #ifdef DEBUG_MACH
 		printf("msg id %d: invalid dest\n", sm->msgh_id);
@@ -195,7 +189,7 @@ mach_msg_send(struct lwp *l, mach_msg_header_t *msg, int *option, size_t send_si
 	 * the remote port.
 	 */
 	rights = (MACH_PORT_TYPE_SEND | MACH_PORT_TYPE_SEND_ONCE);
-	if (mach_right_check(rn, l, rights) == NULL) {
+	if (mach_right_check(rn, td, rights) == NULL) {
 		ret = MACH_SEND_INVALID_RIGHT;
 		goto out1;
 	}
@@ -295,12 +289,12 @@ skip_null_lr:
 		 */
 		reply_size = max_replen;
 		if (lr != NULL)
-			rm = malloc(reply_size, M_EMULDATA, M_WAITOK | M_ZERO);
+			rm = malloc(reply_size, M_MACH, M_WAITOK | M_ZERO);
 		else
 			rm = NULL;
 
 		args.l = l;
-		args.tl = mach_get_target_task(l, mp);
+		args.tl = mach_get_target_task(td, mp);
 		args.smsg = sm;
 		args.rmsg = rm;
 		args.rsize = &reply_size;
@@ -348,7 +342,7 @@ skip_null_lr:
 		wakeup(mp->mp_recv->mr_sethead);
 		ret = MACH_MSG_SUCCESS;
 out1:
-		free(sm, M_EMULDATA);
+		free(sm, M_MACH);
 
 		return ret;
 	}
@@ -363,7 +357,7 @@ out1:
 #ifdef DEBUG_MACH
 		printf("msg id %d: invalid dst\n", sm->msgh_id);
 #endif
-		free(sm, M_EMULDATA);
+		free(sm, M_MACH);
 		return MACH_SEND_INVALID_DEST;
 	}
 
@@ -398,11 +392,11 @@ out1:
  * Receive a Mach message. This returns a Mach message error code.
  */
 static inline int
-mach_msg_recv(struct lwp *l, mach_msg_header_t *urm, int option, size_t recv_size, unsigned int timeout, mach_port_t mn)
+mach_msg_recv(struct thread *td, mach_msg_header_t *urm, int option, size_t recv_size, unsigned int timeout, mach_port_t mn)
 {
 	struct mach_port *mp;
 #if defined(DEBUG_MACH_MSG) || defined(KTRACE)
-	struct proc *p = l->l_proc;
+	struct proc *p = td->td_proc;
 #endif
 	struct mach_message *mm;
 	mach_port_t tmp;
@@ -422,13 +416,13 @@ mach_msg_recv(struct lwp *l, mach_msg_header_t *urm, int option, size_t recv_siz
 	/*
 	 * Check for receive right on the port.
 	 */
-	mr = mach_right_check(mn, l, MACH_PORT_TYPE_RECEIVE);
+	mr = mach_right_check(mn, td, MACH_PORT_TYPE_RECEIVE);
 	if (mr == NULL) {
 
 		/*
 		 * Is it a port set?
 		 */
-		mr = mach_right_check(mn, l, MACH_PORT_TYPE_PORT_SET);
+		mr = mach_right_check(mn, td, MACH_PORT_TYPE_PORT_SET);
 		if (mr == NULL)
 			return MACH_RCV_INVALID_NAME;
 
@@ -438,7 +432,7 @@ mach_msg_recv(struct lwp *l, mach_msg_header_t *urm, int option, size_t recv_siz
 		 * and check if we have some message.
 		 */
 		LIST_FOREACH(cmr, &mr->mr_set, mr_setlist) {
-			if ((mach_right_check(cmr->mr_name, l,
+			if ((mach_right_check(cmr->mr_name, td,
 			    MACH_PORT_TYPE_RECEIVE)) == NULL)
 				return MACH_RCV_INVALID_NAME;
 
@@ -471,7 +465,7 @@ mach_msg_recv(struct lwp *l, mach_msg_header_t *urm, int option, size_t recv_siz
 			 * Check we did not loose the receive right
 			 * while we were sleeping.
 			 */
-			if ((mach_right_check(mn, l,
+			if ((mach_right_check(mn, td,
 			     MACH_PORT_TYPE_PORT_SET)) == NULL)
 				return  MACH_RCV_PORT_DIED;
 
@@ -521,7 +515,7 @@ mach_msg_recv(struct lwp *l, mach_msg_header_t *urm, int option, size_t recv_siz
 			 * Check we did not lose the receive right
 			 * while we were sleeping.
 			 */
-			if ((mach_right_check(mn, l,
+			if ((mach_right_check(mn, td,
 			     MACH_PORT_TYPE_RECEIVE)) == NULL)
 				return MACH_RCV_PORT_DIED;
 
@@ -552,7 +546,7 @@ mach_msg_recv(struct lwp *l, mach_msg_header_t *urm, int option, size_t recv_siz
 		 * If MACH_RCV_LARGE was not set, destroy the message.
 		 */
 		if ((option & MACH_RCV_LARGE) == 0) {
-			free(mm->mm_msg, M_EMULDATA);
+			free(mm->mm_msg, M_MACH);
 			mach_message_put_shlocked(mm);
 			goto unlock;
 		}
@@ -593,18 +587,18 @@ mach_msg_recv(struct lwp *l, mach_msg_header_t *urm, int option, size_t recv_siz
 		 */
 		bits = MACH_MSGH_LOCAL_BITS(mm->mm_msg->msgh_bits);
 		mnp = &mm->mm_msg->msgh_local_port;
-		mach_trade_rights(l, mm->mm_l, mnp, bits);
+		mach_trade_rights(td, mm->mm_l, mnp, bits);
 
 		bits = MACH_MSGH_REMOTE_BITS(mm->mm_msg->msgh_bits);
 		mnp = &mm->mm_msg->msgh_remote_port;
-		mach_trade_rights(l, mm->mm_l, mnp, bits);
+		mach_trade_rights(td, mm->mm_l, mnp, bits);
 
 		/*
 		 * The same operation must be done to all
 		 * port descriptors carried with the message.
 		 */
 		if ((mm->mm_msg->msgh_bits & MACH_MSGH_BITS_COMPLEX) &&
-		    ((ret = mach_trade_rights_complex(l, mm)) != 0))
+		    ((ret = mach_trade_rights_complex(td, mm)) != 0))
 			goto unlock;
 
 		/*
@@ -631,7 +625,7 @@ mach_msg_recv(struct lwp *l, mach_msg_header_t *urm, int option, size_t recv_siz
 	/* Dump the Mach message */
 	ktrmmsg((char *)mm->mm_msg, mm->mm_size);
 
-	free(mm->mm_msg, M_EMULDATA);
+	free(mm->mm_msg, M_MACH);
 	mach_message_put_shlocked(mm); /* decrease mp_count */
 unlock:
 	rw_exit(&mp->mp_msglock);
@@ -641,7 +635,7 @@ unlock:
 
 
 int
-mach_sys_msg_trap(struct lwp *l, const struct mach_sys_msg_trap_args *uap, register_t *retval)
+mach_sys_msg_trap(struct thread *td, const struct mach_sys_msg_trap_args *uap)
 {
 	/* {
 		syscallarg(mach_msg_header_t *) msg;
@@ -654,42 +648,42 @@ mach_sys_msg_trap(struct lwp *l, const struct mach_sys_msg_trap_args *uap, regis
 	} */
 	struct mach_sys_msg_overwrite_trap_args cup;
 
-	SCARG(&cup, msg) = SCARG(uap, msg);
-	SCARG(&cup, option) = SCARG(uap, option);
-	SCARG(&cup, send_size) = SCARG(uap, send_size);
-	SCARG(&cup, rcv_size) = SCARG(uap, rcv_size);
-	SCARG(&cup, rcv_name) = SCARG(uap, rcv_name);
-	SCARG(&cup, timeout) = SCARG(uap, timeout);
-	SCARG(&cup, notify) = SCARG(uap, notify);
-	SCARG(&cup, rcv_msg) = NULL;
-	SCARG(&cup, scatter_list_size) = 0;
-
-	return mach_sys_msg_overwrite_trap(l, &cup, retval);
+	cup.msg = uap->msg;
+	cup.option = uap->option;
+	cup.send_size = uap->send_size;
+	cup.rcv_size = uap->rcv_size;
+	cup.rcv_name = uap->rcv_name;
+	cup.timeout = uap->timeout;
+	cup.notify = uap->notify;
+	cup.rcv_msg = NULL;
+	cup.scatter_list_size = 0;
+
+	return mach_sys_msg_overwrite_trap(td, &cup);
 }
 
-static inline  struct lwp *
-mach_get_target_task(struct lwp *l, struct mach_port *mp)
+static inline  struct thread *
+mach_get_target_task(struct thread *td, struct mach_port *mp)
 {
 	struct proc *tp;
-	struct lwp *tl;
+	struct thread *ttd;
 
 	switch (mp->mp_datatype) {
 	case MACH_MP_PROC:
 		tp = (struct proc *)mp->mp_data;
-		tl = LIST_FIRST(&tp->p_lwps);
+		ttd = TAILQ_FIRST(&tp->p_threads);
 		KASSERT(tl != NULL);
 		break;
 
 	case MACH_MP_LWP:
-		tl = (struct lwp *)mp->mp_data;
+		ttd = (struct thread *)mp->mp_data;
 		break;
 
 	default:
-		tl = l;
+		ttd = td;
 		break;
 	}
 
-	return tl;
+	return ttd;
 }
 
 static inline void
@@ -726,7 +720,7 @@ mach_drop_rights(struct mach_right *mr, int bits)
  * namespace.
  */
 static inline void
-mach_trade_rights(struct lwp *ll, struct lwp *rl, mach_port_t *mnp, int bits)
+mach_trade_rights(struct thread *tdl, struct thread *rl, mach_port_t *mnp, int bits)
 	/* ll:		 local lwp (receiver, current lwp) */
 	/* rl:		 remote lwp (sender) */
 	/* mnp:	 pointer to the port name */
@@ -794,7 +788,7 @@ mach_trade_rights(struct lwp *ll, struct lwp *rl, mach_port_t *mnp, int bits)
  * is not done yet.
  */
 static inline int
-mach_trade_rights_complex(struct lwp *l, struct mach_message *mm)
+mach_trade_rights_complex(struct thread *td, struct mach_message *mm)
 {
 	struct mach_complex_msg *mcm;
 	unsigned int i, count;
@@ -828,7 +822,7 @@ mach_trade_rights_complex(struct lwp *l, struct mach_message *mm)
 			break;
 
 		case MACH_MSG_OOL_PORTS_DESCRIPTOR: {	/* XXX untested */
-			struct lwp *rl;		/* remote LWP */
+			struct thread *rl;		/* remote LWP */
 			void *lumnp;		/* local user address */
 			void *rumnp;		/* remote user address */
 			int disp;		/* disposition*/
@@ -871,7 +865,7 @@ mach_trade_rights_complex(struct lwp *l, struct mach_message *mm)
 #endif
 			/* FALLTHROUGH */
 		case MACH_MSG_OOL_DESCRIPTOR: {	/* XXX untested */
-			struct lwp *rl;		/* remote LWP */
+			struct thread *rl;		/* remote LWP */
 			void *ludata;		/* local user address */
 			void *rudata;		/* remote user address */
 			size_t size;		/* data size */
@@ -915,11 +909,11 @@ mach_trade_rights_complex(struct lwp *l, struct mach_message *mm)
 }
 
 inline int
-mach_ool_copyin(struct lwp *l, const void *uaddr, void **kaddr, size_t size, int flags)
+mach_ool_copyin(struct thread *td, const void *uaddr, void **kaddr, size_t size, int flags)
 {
 	int error;
 	void *kbuf;
-	struct proc *p = l->l_proc;
+	struct proc *p = td->td_proc;
 
 	/*
 	 * Sanity check OOL size to avoid DoS on malloc: useless once
@@ -932,13 +926,13 @@ mach_ool_copyin(struct lwp *l, const void *uaddr, void **kaddr, size_t size, int
 #endif
 
 	if (*kaddr == NULL)
-		kbuf = malloc(size, M_EMULDATA, M_WAITOK);
+		kbuf = malloc(size, M_MACH, M_WAITOK);
 	else
 		kbuf = *kaddr;
 
 	if ((error = copyin_proc(p, uaddr, kbuf, size)) != 0) {
 		if (*kaddr == NULL)
-			free(kbuf, M_EMULDATA);
+			free(kbuf, M_MACH);
 		return error;
 	}
 
@@ -952,11 +946,11 @@ mach_ool_copyin(struct lwp *l, const void *uaddr, void **kaddr, size_t size, int
 }
 
 inline int
-mach_ool_copyout(struct lwp *l, const void *kaddr, void **uaddr, size_t size, int flags)
+mach_ool_copyout(struct thread *td, const void *kaddr, void **uaddr, size_t size, int flags)
 {
-	vaddr_t ubuf;
+	vm_offset_t ubuf;
 	int error = 0;
-	struct proc *p = l->l_proc;
+	struct proc *p = td->td_proc;
 
 	/*
 	 * Sanity check OOL size to avoid DoS on malloc: useless once
@@ -971,12 +965,12 @@ mach_ool_copyout(struct lwp *l, const void *kaddr, void **uaddr, size_t size, in
 #endif
 
 	if (*uaddr == NULL)
-		ubuf = (vaddr_t)vm_map_min(&p->p_vmspace->vm_map);
+		ubuf = (vm_offset_t)vm_map_min(&p->p_vmspace->vm_map);
 	else
-		ubuf = (vaddr_t)*uaddr;
+		ubuf = (vm_offset_t)*uaddr;
 
 	/* Never map anything at address zero: this is a red zone */
-	if (ubuf == (vaddr_t)NULL)
+	if (ubuf == (vm_offset_t)NULL)
 		ubuf += PAGE_SIZE;
 
 	if ((error = uvm_map(&p->p_vmspace->vm_map, &ubuf,
@@ -995,7 +989,7 @@ mach_ool_copyout(struct lwp *l, const void *kaddr, void **uaddr, size_t size, in
 
 out:
 	if (flags & MACH_OOL_FREE)
-		free(__UNCONST(kaddr), M_EMULDATA); /*XXXUNCONST*/
+		free(__UNCONST(kaddr), M_MACH); /*XXXUNCONST*/
 
 	if (error == 0)
 		*uaddr = (void *)ubuf;
@@ -1110,7 +1104,7 @@ mach_message_init(void)
 }
 
 struct mach_message *
-mach_message_get(mach_msg_header_t *msgh, size_t size, struct mach_port *mp, struct lwp *l)
+mach_message_get(mach_msg_header_t *msgh, size_t size, struct mach_port *mp, struct thread *td)
 {
 	struct mach_message *mm;
 
@@ -1180,7 +1174,7 @@ mach_message_put_exclocked(struct mach_message *mm)
 void
 mach_debug_message(void)
 {
-	struct lwp *l;
+	struct thread *td;
 	struct mach_emuldata *med;
 	struct mach_right *mr;
 	struct mach_right *mrs;
@@ -1188,14 +1182,14 @@ mach_debug_message(void)
 	struct mach_message *mm;
 
 	LIST_FOREACH(l, &alllwp, l_list) {
-		if ((l->l_proc->p_emul != &emul_mach) &&
+		if ((td->td_proc->p_emul != &emul_mach) &&
 #ifdef COMPAT_DARWIN
-		    (l->l_proc->p_emul != &emul_darwin) &&
+		    (td->td_proc->p_emul != &emul_darwin) &&
 #endif
 		    1)
 			continue;
 
-		med = l->l_proc->p_emuldata;
+		med = td->td_proc->p_emuldata;
 		LIST_FOREACH(mr, &med->med_right, mr_list)
 			if ((mr->mr_type & MACH_PORT_TYPE_PORT_SET) == 0) {
 				mp = mr->mr_port;
diff --git a/sys/compat/mach/mach_message.h b/sys/compat/mach/mach_message.h
index 570a336..72f6836 100644
--- a/sys/compat/mach/mach_message.h
+++ b/sys/compat/mach/mach_message.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_message.h,v 1.30 2008/04/28 20:23:44 martin Exp $	 */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
@@ -223,8 +223,8 @@ struct mach_complex_msg {
 /* Kernel-private structures */
 
 struct mach_trap_args {
-	struct lwp *l;	/* Current task (doing the Mach system call) */
-	struct lwp *tl; /* Target task */
+	struct thread *td;	/* Current task (doing the Mach system call) */
+	struct thread *ttd; /* Target task */
 	void *smsg;	/* Sent message */
 	void *rmsg;	/* Reply message */
 	size_t ssize;	/* Sent message size */
@@ -248,7 +248,7 @@ struct mach_message {
 	TAILQ_ENTRY(mach_message) mm_list;
 					/* List of pending messages */
 	struct mach_port *mm_port;	/* The port on which msg is queued */
-	struct lwp *mm_l;		/* The thread that sent it */
+	struct thread *mm_l;		/* The thread that sent it */
 };
 
 /* Flags for mach_ool_copy{in|out} */
@@ -256,16 +256,16 @@ struct mach_message {
 #define MACH_OOL_FREE	0x1	/* Free kernel buffer after copyout */
 #define MACH_OOL_TRACE	0x2	/* ktrace OOL data */
 
-__inline int mach_ool_copyin(struct lwp *, const void *, void **, size_t, int);
-__inline int mach_ool_copyout(struct lwp *, const void *, void **, size_t, int);
-__inline void mach_set_trailer(void *, size_t);
-__inline void mach_set_header(void *, void *, size_t);
-__inline void mach_add_port_desc(void *, mach_port_name_t);
-__inline void mach_add_ool_ports_desc(void *, void *, int);
-__inline void mach_add_ool_desc(void *, void *, size_t);
+int mach_ool_copyin(struct thread *, const void *, void **, size_t, int);
+int mach_ool_copyout(struct thread *, const void *, void **, size_t, int);
+void mach_set_trailer(void *, size_t);
+void mach_set_header(void *, void *, size_t);
+void mach_add_port_desc(void *, mach_port_name_t);
+void mach_add_ool_ports_desc(void *, void *, int);
+void mach_add_ool_desc(void *, void *, size_t);
 void mach_message_init(void);
 struct mach_message *mach_message_get(mach_msg_header_t *,
-    size_t, struct mach_port *, struct lwp *);
+    size_t, struct mach_port *, struct thread *);
 void mach_message_put(struct mach_message *);
 void mach_message_put_shlocked(struct mach_message *);
 void mach_message_put_exclocked(struct mach_message *);
diff --git a/sys/compat/mach/mach_misc.c b/sys/compat/mach/mach_misc.c
index 84f9c83..5df2eb1 100644
--- a/sys/compat/mach/mach_misc.c
+++ b/sys/compat/mach/mach_misc.c
@@ -1,5 +1,3 @@
-/*	$NetBSD: mach_misc.c,v 1.28 2008/04/28 20:23:44 martin Exp $	 */
-
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -36,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_misc.c,v 1.28 2008/04/28 20:23:44 martin Exp $");
+__FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -69,149 +67,135 @@ __KERNEL_RCSID(0, "$NetBSD: mach_misc.c,v 1.28 2008/04/28 20:23:44 martin Exp $"
 #include <sys/signalvar.h>
 
 #include <netinet/in.h>
-#include <sys/syscallargs.h>
+#include <sys/sysproto.h>
 
 #include <miscfs/specfs/specdev.h>
 
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
 #include <compat/mach/mach_clock.h>
-#include <compat/mach/mach_syscallargs.h>
+#include <compat/mach/mach_proto.h>
 
 
 int
-mach_sys_semaphore_timedwait_trap(struct lwp *l, const struct mach_sys_semaphore_timedwait_trap_args *uap, register_t *retval)
+mach_sys_semaphore_timedwait_trap(struct thread *td, const struct mach_sys_semaphore_timedwait_trap_args *uap)
 {
 
-	*retval = 0;
 	DPRINTF(("mach_sys_semaphore_timedwait_trap(0x%x, %d, %d);\n",
-	    SCARG(uap, wait_name), SCARG(uap, sec), SCARG(uap, nsec)));
+	    uap->wait_name, uap->sec, uap->nsec));
 	return 0;
 }
 
 
 int
-mach_sys_semaphore_timedwait_signal_trap(struct lwp *l, const struct mach_sys_semaphore_timedwait_signal_trap_args *uap, register_t *retval)
+mach_sys_semaphore_timedwait_signal_trap(struct thread *td, const struct mach_sys_semaphore_timedwait_signal_trap_args *uap)
 {
 
-	*retval = 0;
 	DPRINTF((
 	    "mach_sys_semaphore_timedwait_signal_trap(0x%x, 0x%x, %d, %d);\n",
-	    SCARG(uap, wait_name), SCARG(uap, signal_name), SCARG(uap, sec),
-	    SCARG(uap, nsec)));
+	    uap->wait_name, uap->signal_name, uap->sec,
+	    uap->nsec));
 	return 0;
 }
 
 
 int
-mach_sys_init_process(struct lwp *l, const void *v, register_t *retval)
+mach_sys_init_process(struct thread *td, const void *v)
 {
-	*retval = 0;
 	DPRINTF(("mach_sys_init_process();\n"));
 	return 0;
 }
 
 
 int
-mach_sys_pid_for_task(struct lwp *l, const struct mach_sys_pid_for_task_args *uap, register_t *retval)
+mach_sys_pid_for_task(struct thread *td, const struct mach_sys_pid_for_task_args *uap)
 {
 
-	*retval = 0;
 	DPRINTF(("mach_sys_pid_for_task(0x%x, %p);\n",
-	    SCARG(uap, t), SCARG(uap, x)));
+	    uap->t, uap->x));
 	return 0;
 }
 
 
 int
-mach_sys_macx_swapon(struct lwp *l, const struct mach_sys_macx_swapon_args *uap, register_t *retval)
+mach_sys_macx_swapon(struct thread *td, const struct mach_sys_macx_swapon_args *uap)
 {
 
-	*retval = 0;
 	DPRINTF(("mach_sys_macx_swapon(%p, %d, %d, %d);\n",
-	    SCARG(uap, name), SCARG(uap, flags), SCARG(uap, size),
-	    SCARG(uap, priority)));
+	    uap->name, uap->flags, uap->size,
+			 uap->priority));
 	return 0;
 }
 
 int
-mach_sys_macx_swapoff(struct lwp *l, const struct mach_sys_macx_swapoff_args *uap, register_t *retval)
+mach_sys_macx_swapoff(struct thread *td, const struct mach_sys_macx_swapoff_args *uap)
 {
 
-	*retval = 0;
 	DPRINTF(("mach_sys_macx_swapoff(%p, %d);\n",
-	    SCARG(uap, name), SCARG(uap, flags)));
+			 uap->name, uap->flags));
 	return 0;
 }
 
 int
-mach_sys_macx_triggers(struct lwp *l, const struct mach_sys_macx_triggers_args *uap, register_t *retval)
+mach_sys_macx_triggers(struct thread *td, const struct mach_sys_macx_triggers_args *uap)
 {
 
-	*retval = 0;
 	DPRINTF(("mach_sys_macx_triggers(%d, %d, %d, 0x%x);\n",
-	    SCARG(uap, hi_water), SCARG(uap, low_water), SCARG(uap, flags),
-	    SCARG(uap, alert_port)));
+	    uap->hi_water, uap->low_water, uap->flags,
+			 uap->alert_port));
 	return 0;
 }
 
 
 int
-mach_sys_wait_until(struct lwp *l, const struct mach_sys_wait_until_args *uap, register_t *retval)
+mach_sys_wait_until(struct thread *td, const struct mach_sys_wait_until_args *uap)
 {
 
-	*retval = 0;
-	DPRINTF(("mach_sys_wait_until(%lld);\n",
-	    SCARG(uap, deadline)));
+	DPRINTF(("mach_sys_wait_until(%lld);\n", uap->deadline));
 	return 0;
 }
 
 
 int
-mach_sys_timer_create(struct lwp *l, const void *v, register_t *retval)
+mach_sys_timer_create(struct thread *td, const void *v)
 {
-	*retval = 0;
 	DPRINTF(("mach_sys_timer_create();\n"));
 	return 0;
 }
 
 
 int
-mach_sys_timer_destroy(struct lwp *l, const struct mach_sys_timer_destroy_args *uap, register_t *retval)
+mach_sys_timer_destroy(struct thread *td, const struct mach_sys_timer_destroy_args *uap)
 {
 
-	*retval = 0;
-	DPRINTF(("mach_sys_timer_destroy(0x%x);\n", SCARG(uap, name)));
+	DPRINTF(("mach_sys_timer_destroy(0x%x);\n", uap->name));
 	return 0;
 }
 
 
 int
-mach_sys_timer_arm(struct lwp *l, const struct mach_sys_timer_arm_args *uap, register_t *retval)
+mach_sys_timer_arm(struct thread *td, const struct mach_sys_timer_arm_args *uap)
 {
 
-	*retval = 0;
 	DPRINTF(("mach_sys_timer_arm(0x%x, %d);\n",
-	    SCARG(uap, name), SCARG(uap, expire_time)));
+	    uap->name, uap->expire_time));
 	return 0;
 }
 
 
 int
-mach_sys_timer_cancel(struct lwp *l, const struct mach_sys_timer_cancel_args *uap, register_t *retval)
+mach_sys_timer_cancel(struct thread *td, const struct mach_sys_timer_cancel_args *uap)
 {
 
-	*retval = 0;
 	DPRINTF(("mach_sys_timer_cancel(0x%x, %p);\n",
-	    SCARG(uap, name), SCARG(uap, result_time)));
+	    uap->name, uap->result_time));
 	return 0;
 }
 
 
 int
-mach_sys_get_time_base_info(struct lwp *l, const void *v, register_t *retval)
+mach_sys_get_time_base_info(struct thread *td, const void *v)
 {
-	*retval = 0;
 	DPRINTF(("mach_sys_get_time_base_info();\n"));
 	return 0;
 }
diff --git a/sys/compat/mach/mach_notify.c b/sys/compat/mach/mach_notify.c
index 3f5f8fb..6017c9a 100644
--- a/sys/compat/mach/mach_notify.c
+++ b/sys/compat/mach/mach_notify.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_notify.c,v 1.20 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -30,11 +30,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_notify.c,v 1.20 2008/04/28 20:23:44 martin Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/signal.h>
+#include <sys/systm.h>
 #include <sys/proc.h>
 #include <sys/malloc.h>
 
@@ -46,7 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: mach_notify.c,v 1.20 2008/04/28 20:23:44 martin Exp
 #include <compat/mach/mach_services.h>
 
 void
-mach_notify_port_destroyed(struct lwp *l, struct mach_right *mr)
+mach_notify_port_destroyed(struct thread *td, struct mach_right *mr)
 {
 	struct mach_port *mp;
 	mach_notify_port_destroyed_request_t *req;
@@ -65,7 +65,7 @@ mach_notify_port_destroyed(struct lwp *l, struct mach_right *mr)
 
 	MACH_PORT_REF(mp);
 
-	req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
+	req = malloc(sizeof(*req), M_MACH, M_WAITOK | M_ZERO);
 
 	req->req_msgh.msgh_bits =
 	    MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
@@ -77,10 +77,10 @@ mach_notify_port_destroyed(struct lwp *l, struct mach_right *mr)
 
 	mach_set_trailer(req, sizeof(*req));
 
-	(void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, l);
+	(void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, td);
 #ifdef DEBUG_MACH_MSG
 	printf("pid %d: message queued on port %p (%d) [%p]\n",
-	    l->l_proc->p_pid, mp, req->req_msgh.msgh_id,
+	    td->td_proc->p_pid, mp, req->req_msgh.msgh_id,
 	    mp->mp_recv->mr_sethead);
 #endif
 	wakeup(mp->mp_recv->mr_sethead);
@@ -91,7 +91,7 @@ mach_notify_port_destroyed(struct lwp *l, struct mach_right *mr)
 }
 
 void
-mach_notify_port_no_senders(struct lwp *l, struct mach_right *mr)
+mach_notify_port_no_senders(struct thread *td, struct mach_right *mr)
 {
 	struct mach_port *mp;
 	mach_notify_port_no_senders_request_t *req;
@@ -113,7 +113,7 @@ mach_notify_port_no_senders(struct lwp *l, struct mach_right *mr)
 	if ((int)mp->mp_data >= mr->mr_refcount)
 		goto out;
 
-	req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
+	req = malloc(sizeof(*req), M_MACH, M_WAITOK | M_ZERO);
 
 	req->req_msgh.msgh_bits =
 	    MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
@@ -124,10 +124,10 @@ mach_notify_port_no_senders(struct lwp *l, struct mach_right *mr)
 
 	mach_set_trailer(req, sizeof(*req));
 
-	(void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, l);
+	(void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, td);
 #ifdef DEBUG_MACH_MSG
 	printf("pid %d: message queued on port %p (%d) [%p]\n",
-	    l->l_proc->p_pid, mp, req->req_msgh.msgh_id,
+	    td->td_proc->p_pid, mp, req->req_msgh.msgh_id,
 	    mp->mp_recv->mr_sethead);
 #endif
 	wakeup(mp->mp_recv->mr_sethead);
@@ -138,7 +138,7 @@ out:
 }
 
 void
-mach_notify_port_dead_name(struct lwp *l, struct mach_right *mr)
+mach_notify_port_dead_name(struct thread *td, struct mach_right *mr)
 {
 	struct mach_port *mp;
 	mach_notify_port_dead_name_request_t *req;
@@ -156,7 +156,7 @@ mach_notify_port_dead_name(struct lwp *l, struct mach_right *mr)
 #endif
 	MACH_PORT_REF(mp);
 
-	req = malloc(sizeof(*req), M_EMULDATA, M_WAITOK | M_ZERO);
+	req = malloc(sizeof(*req), M_MACH, M_WAITOK | M_ZERO);
 
 	req->req_msgh.msgh_bits =
 	    MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
@@ -169,10 +169,10 @@ mach_notify_port_dead_name(struct lwp *l, struct mach_right *mr)
 
 	mr->mr_refcount++;
 
-	(void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, l);
+	(void)mach_message_get((mach_msg_header_t *)req, sizeof(*req), mp, td);
 #ifdef DEBUG_MACH_MSG
 	printf("pid %d: message queued on port %p (%d) [%p]\n",
-	    l->l_proc->p_pid, mp, req->req_msgh.msgh_id,
+	    td->td_proc->p_pid, mp, req->req_msgh.msgh_id,
 	    mp->mp_recv->mr_sethead);
 #endif
 	wakeup(mp->mp_recv->mr_sethead);
diff --git a/sys/compat/mach/mach_notify.h b/sys/compat/mach/mach_notify.h
index 06b2bd4..a413854 100644
--- a/sys/compat/mach/mach_notify.h
+++ b/sys/compat/mach/mach_notify.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_notify.h,v 1.10 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -71,9 +71,9 @@ typedef struct {
 	mach_msg_trailer_t req_trailer;
 } mach_notify_port_dead_name_request_t;
 
-void mach_notify_port_destroyed(struct lwp *, struct mach_right *);
-void mach_notify_port_no_senders(struct lwp *, struct mach_right *);
-void mach_notify_port_dead_name(struct lwp *, struct mach_right *);
+void mach_notify_port_destroyed(struct thread *, struct mach_right *);
+void mach_notify_port_no_senders(struct thread *, struct mach_right *);
+void mach_notify_port_dead_name(struct thread *, struct mach_right *);
 
 #endif /* _MACH_NOTIFICATION_H_ */
 
diff --git a/sys/compat/mach/mach_port.c b/sys/compat/mach/mach_port.c
index a891600..0b0efc9 100644
--- a/sys/compat/mach/mach_port.c
+++ b/sys/compat/mach/mach_port.c
@@ -1,5 +1,3 @@
-/*	$NetBSD: mach_port.c,v 1.66 2009/03/18 16:00:17 cegger Exp $ */
-
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -9,12 +7,12 @@
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
+ * are met: 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.  2. Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -29,10 +27,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "opt_compat_darwin.h"
-
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_port.c,v 1.66 2009/03/18 16:00:17 cegger Exp $");
+__FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -52,7 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: mach_port.c,v 1.66 2009/03/18 16:00:17 cegger Exp $"
 #include <compat/mach/mach_errno.h>
 #include <compat/mach/mach_notify.h>
 #include <compat/mach/mach_services.h>
-#include <compat/mach/mach_syscallargs.h>
+#include <compat/mach/mach_proto.h>
 
 #ifdef COMPAT_DARWIN
 #include <compat/darwin/darwin_exec.h>
@@ -68,53 +64,53 @@ struct mach_port *mach_io_master_port;
 struct mach_port *mach_saved_bootstrap_port;
 
 int
-mach_sys_reply_port(struct lwp *l, const void *v, register_t *retval)
+mach_sys_reply_port(struct thread *td, const void *v)
 {
 	struct mach_right *mr;
 
-	mr = mach_right_get(mach_port_get(), l, MACH_PORT_TYPE_RECEIVE, 0);
-	*retval = (register_t)mr->mr_name;
+	mr = mach_right_get(mach_port_get(), td, MACH_PORT_TYPE_RECEIVE, 0);
+	td->td_retval[0] = (register_t)mr->mr_name;
 
 	return 0;
 }
 
 int
-mach_sys_thread_self_trap(struct lwp *l, const void *v, register_t *retval)
+mach_sys_thread_self_trap(struct thread *td, const void *v)
 {
 	struct mach_lwp_emuldata *mle;
 	struct mach_right *mr;
 
 	mle = l->l_emuldata;
-	mr = mach_right_get(mle->mle_kernel, l, MACH_PORT_TYPE_SEND, 0);
-	*retval = (register_t)mr->mr_name;
+	mr = mach_right_get(mle->mle_kernel, td, MACH_PORT_TYPE_SEND, 0);
+	td->td_retval[0] = (register_t)mr->mr_name;
 
 	return 0;
 }
 
 
 int
-mach_sys_task_self_trap(struct lwp *l, const void *v, register_t *retval)
+mach_task_self_trap(struct thread *td, const void *v)
 {
 	struct mach_emuldata *med;
 	struct mach_right *mr;
 
-	med = (struct mach_emuldata *)l->l_proc->p_emuldata;
-	mr = mach_right_get(med->med_kernel, l, MACH_PORT_TYPE_SEND, 0);
-	*retval = (register_t)mr->mr_name;
+	med = (struct mach_emuldata *)td->td_proc->p_emuldata;
+	mr = mach_right_get(med->med_kernel, td, MACH_PORT_TYPE_SEND, 0);
+	td->td_retval[0] = (register_t)mr->mr_name;
 
 	return 0;
 }
 
 
 int
-mach_sys_host_self_trap(struct lwp *l, const void *v, register_t *retval)
+mach_sys_host_self_trap(struct thread *td, const void *v)
 {
 	struct mach_emuldata *med;
 	struct mach_right *mr;
 
-	med = (struct mach_emuldata *)l->l_proc->p_emuldata;
-	mr = mach_right_get(med->med_host, l, MACH_PORT_TYPE_SEND, 0);
-	*retval = (register_t)mr->mr_name;
+	med = (struct mach_emuldata *)td->td_proc->p_emuldata;
+	mr = mach_right_get(med->med_host, td, MACH_PORT_TYPE_SEND, 0);
+	td->td_retval[0] = (register_t)mr->mr_name;
 
 	return 0;
 }
@@ -125,12 +121,12 @@ mach_port_deallocate(struct mach_trap_args *args)
 	mach_port_deallocate_request_t *req = args->smsg;
 	mach_port_deallocate_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 
 	mn = req->req_name;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_REF_RIGHTS)) != NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_REF_RIGHTS)) != NULL)
 		mach_right_put(mr, MACH_PORT_TYPE_REF_RIGHTS);
 
 	*msglen = sizeof(*rep);
@@ -149,7 +145,7 @@ mach_port_destroy(struct mach_trap_args *args)
 	mach_port_destroy_request_t *req = args->smsg;
 	mach_port_destroy_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 
@@ -158,7 +154,7 @@ mach_port_destroy(struct mach_trap_args *args)
 #endif
 	mn = req->req_name;
 	if ((mr = mach_right_check(mn,
-	    l, MACH_PORT_TYPE_ALL_RIGHTS)) != NULL) {
+	    td, MACH_PORT_TYPE_ALL_RIGHTS)) != NULL) {
 		MACH_PORT_UNREF(mr->mr_port);
 		mr->mr_port = NULL;
 		mach_right_put(mr, MACH_PORT_TYPE_ALL_RIGHTS);
@@ -180,22 +176,22 @@ mach_port_allocate(struct mach_trap_args *args)
 	mach_port_allocate_request_t *req = args->smsg;
 	mach_port_allocate_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_right *mr;
 	struct mach_port *mp;
 
 	switch (req->req_right) {
 	case MACH_PORT_RIGHT_RECEIVE:
 		mp = mach_port_get();
-		mr = mach_right_get(mp, l, MACH_PORT_TYPE_RECEIVE, 0);
+		mr = mach_right_get(mp, td, MACH_PORT_TYPE_RECEIVE, 0);
 		break;
 
 	case MACH_PORT_RIGHT_DEAD_NAME:
-		mr = mach_right_get(NULL, l, MACH_PORT_TYPE_DEAD_NAME, 0);
+		mr = mach_right_get(NULL, td, MACH_PORT_TYPE_DEAD_NAME, 0);
 		break;
 
 	case MACH_PORT_RIGHT_PORT_SET:
-		mr = mach_right_get(NULL, l, MACH_PORT_TYPE_PORT_SET, 0);
+		mr = mach_right_get(NULL, td, MACH_PORT_TYPE_PORT_SET, 0);
 		break;
 
 	default:
@@ -222,7 +218,7 @@ mach_port_insert_right(struct mach_trap_args *args)
 	mach_port_insert_right_request_t *req = args->smsg;
 	mach_port_insert_right_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t name;
 	mach_port_t right;
 	struct mach_right *mr;
@@ -232,7 +228,7 @@ mach_port_insert_right(struct mach_trap_args *args)
 	right = req->req_poly.name;
 	nmr = NULL;
 
-	mr = mach_right_check(right, l, MACH_PORT_TYPE_ALL_RIGHTS);
+	mr = mach_right_check(right, td, MACH_PORT_TYPE_ALL_RIGHTS);
 	if (mr == NULL)
 		return mach_msg_error(args, EPERM);
 
@@ -241,18 +237,18 @@ mach_port_insert_right(struct mach_trap_args *args)
 	case MACH_MSG_TYPE_MOVE_SEND:
 	case MACH_MSG_TYPE_COPY_SEND:
 		nmr = mach_right_get(mr->mr_port,
-		    l, MACH_PORT_TYPE_SEND, name);
+		    td, MACH_PORT_TYPE_SEND, name);
 		break;
 
 	case MACH_MSG_TYPE_MAKE_SEND_ONCE:
 	case MACH_MSG_TYPE_MOVE_SEND_ONCE:
 		nmr = mach_right_get(mr->mr_port,
-		    l, MACH_PORT_TYPE_SEND_ONCE, name);
+		    td, MACH_PORT_TYPE_SEND_ONCE, name);
 		break;
 
 	case MACH_MSG_TYPE_MOVE_RECEIVE:
 		nmr = mach_right_get(mr->mr_port,
-		    l, MACH_PORT_TYPE_RECEIVE, name);
+		    td, MACH_PORT_TYPE_RECEIVE, name);
 		break;
 
 	default:
@@ -277,12 +273,12 @@ mach_port_type(struct mach_trap_args *args)
 	mach_port_type_request_t *req = args->smsg;
 	mach_port_type_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 
 	mn = req->req_name;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_msg_error(args, EPERM);
 
 	*msglen = sizeof(*rep);
@@ -336,7 +332,7 @@ mach_port_get_attributes(struct mach_trap_args *args)
 	mach_port_get_attributes_request_t *req = args->smsg;
 	mach_port_get_attributes_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 
@@ -345,7 +341,7 @@ mach_port_get_attributes(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 
 	mn = req->req_msgh.msgh_remote_port;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_msg_error(args, EPERM);
 
 	switch (req->req_flavor) {
@@ -440,18 +436,18 @@ mach_port_move_member(struct mach_trap_args *args)
 	mach_port_move_member_request_t *req = args->smsg;
 	mach_port_move_member_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
-	struct mach_emuldata *med = l->l_proc->p_emuldata;
+	struct thread *td = args->td;
+	struct mach_emuldata *med = td->td_proc->p_emuldata;
 	mach_port_t member = req->req_member;
 	mach_port_t after = req->req_after;
 	struct mach_right *mrr;
 	struct mach_right *mrs;
 
-	mrr = mach_right_check(member, l, MACH_PORT_TYPE_RECEIVE);
+	mrr = mach_right_check(member, td, MACH_PORT_TYPE_RECEIVE);
 	if (mrr == NULL)
 		return mach_msg_error(args, EPERM);
 
-	mrs = mach_right_check(after, l, MACH_PORT_TYPE_PORT_SET);
+	mrs = mach_right_check(after, td, MACH_PORT_TYPE_PORT_SET);
 	if (mrs == NULL)
 		return mach_msg_error(args, EPERM);
 
@@ -482,7 +478,7 @@ mach_port_request_notification(struct mach_trap_args *args)
 {
 	mach_port_request_notification_request_t *req = args->smsg;
 	mach_port_request_notification_reply_t *rep = args->rmsg;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	size_t *msglen = args->rsize;
 	mach_port_t mn;
 	struct mach_right *nmr;
@@ -495,11 +491,11 @@ mach_port_request_notification(struct mach_trap_args *args)
 	    req->req_notify.name, mn = req->req_name);
 #endif
 	mn = req->req_notify.name;
-	if ((nmr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((nmr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_msg_error(args, EINVAL);
 
 	mn = req->req_name;
-	if ((tmr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((tmr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return mach_msg_error(args, EINVAL);
 
 #ifdef DEBUG_MACH
@@ -516,13 +512,13 @@ mach_port_request_notification(struct mach_trap_args *args)
 	case MACH_NOTIFY_DESTROYED_MSGID:
 		oldnmr = tmr->mr_notify_destroyed;
 		tmr->mr_notify_destroyed = mach_right_get(nmr->mr_port,
-		    l, MACH_PORT_TYPE_SEND_ONCE, req->req_notify.name);
+		    td, MACH_PORT_TYPE_SEND_ONCE, req->req_notify.name);
 		break;
 
 	case MACH_NOTIFY_NO_SENDERS_MSGID:
 		oldnmr = tmr->mr_notify_no_senders;
 		tmr->mr_notify_no_senders = mach_right_get(nmr->mr_port,
-		    l, MACH_PORT_TYPE_SEND_ONCE, req->req_notify.name);
+		    td, MACH_PORT_TYPE_SEND_ONCE, req->req_notify.name);
 		tmr->mr_notify_no_senders->mr_port->mp_datatype =
 		    MACH_MP_NOTIFY_SYNC;
 		tmr->mr_notify_no_senders->mr_port->mp_data = (void *)
@@ -532,7 +528,7 @@ mach_port_request_notification(struct mach_trap_args *args)
 	case MACH_NOTIFY_DEAD_NAME_MSGID:
 		oldnmr = tmr->mr_notify_dead_name;
 		tmr->mr_notify_dead_name = mach_right_get(nmr->mr_port,
-		    l, MACH_PORT_TYPE_SEND_ONCE, req->req_notify.name);
+		    td, MACH_PORT_TYPE_SEND_ONCE, req->req_notify.name);
 		break;
 
 	case MACH_NOTIFY_SEND_ONCE_MSGID:
@@ -566,13 +562,13 @@ mach_port_get_refs(struct mach_trap_args *args)
 	mach_port_get_refs_request_t *req = args->smsg;
 	mach_port_get_refs_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 	mach_port_right_t right = req->req_right;
 
 	mn = req->req_name;
-	if ((mr = mach_right_check(mn, l, right)) == NULL)
+	if ((mr = mach_right_check(mn, td, right)) == NULL)
 		return mach_msg_error(args, EINVAL);
 
 	*msglen = sizeof(*rep);
@@ -593,13 +589,13 @@ mach_port_mod_refs(struct mach_trap_args *args)
 	mach_port_mod_refs_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
 #if 0
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	mach_port_t mn;
 	struct mach_right *mr;
 	mach_port_right_t right = req->req_right;
 
 	mn = req->req_name;
-	if ((mr = mach_right_check(mn, l, right)) == NULL)
+	if ((mr = mach_right_check(mn, td, right)) == NULL)
 		return mach_msg_error(args, EINVAL);
 
 	/*
@@ -680,7 +676,7 @@ mach_port_put(struct mach_port *mp)
 	rw_destroy(&mp->mp_msglock);
 
 	if (mp->mp_flags & MACH_MP_DATA_ALLOCATED)
-		free(mp->mp_data, M_EMULDATA);
+		free(mp->mp_data, M_MACH);
 
 	pool_put(&mach_port_pool, mp);
 
@@ -688,7 +684,7 @@ mach_port_put(struct mach_port *mp)
 }
 
 struct mach_right *
-mach_right_get(struct mach_port *mp, struct lwp *l, int type, mach_port_t hint)
+mach_right_get(struct mach_port *mp, struct thread *td, int type, mach_port_t hint)
 {
 	struct mach_right *mr;
 	struct mach_emuldata *med;
@@ -698,7 +694,7 @@ mach_right_get(struct mach_port *mp, struct lwp *l, int type, mach_port_t hint)
 	if (type == 0)
 		uprintf("mach_right_get: right = 0\n");
 #endif
-	med = (struct mach_emuldata *)l->l_proc->p_emuldata;
+	med = (struct mach_emuldata *)td->td_proc->p_emuldata;
 
 	if (mp != NULL)
 		MACH_PORT_REF(mp);
@@ -888,7 +884,7 @@ mach_right_put_exclocked(struct mach_right *mr, int right)
  * Check that a process has a given right.
  */
 struct mach_right *
-mach_right_check(mach_port_t mn, struct lwp *l, int type)
+mach_right_check(mach_port_t mn, struct thread *td, int type)
 {
 	struct mach_right *cmr;
 	struct mach_emuldata *med;
@@ -896,7 +892,7 @@ mach_right_check(mach_port_t mn, struct lwp *l, int type)
 	if ((mn == 0) || (mn == -1) || (l == NULL))
 		return NULL;
 
-	med = (struct mach_emuldata *)l->l_proc->p_emuldata;
+	med = (struct mach_emuldata *)td->td_proc->p_emuldata;
 
 	rw_enter(&med->med_rightlock, RW_READER);
 
@@ -925,13 +921,13 @@ mach_right_check(mach_port_t mn, struct lwp *l, int type)
  * Right lists should be locked.
  */
 mach_port_t
-mach_right_newname(struct lwp *l, mach_port_t hint)
+mach_right_newname(struct thread *td, mach_port_t hint)
 {
 	struct mach_emuldata *med;
 	struct mach_right *mr;
 	mach_port_t newname = -1;
 
-	med = l->l_proc->p_emuldata;
+	med = td->td_proc->p_emuldata;
 
 	if (hint == 0)
 		hint = med->med_nextright;
diff --git a/sys/compat/mach/mach_port.h b/sys/compat/mach/mach_port.h
index 8399791..4c9cb6b 100644
--- a/sys/compat/mach/mach_port.h
+++ b/sys/compat/mach/mach_port.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_port.h,v 1.40 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -31,6 +31,8 @@
 
 #ifndef	_MACH_PORT_H_
 #define	_MACH_PORT_H_
+#include <sys/lock.h>
+#include <sys/rwlock.h>
 
 #define MACH_PORT_REF(mp)	(mp)->mp_refcount++
 #define MACH_PORT_UNREF(mp)	if (--(mp)->mp_refcount <= 0) mach_port_put(mp)
@@ -294,7 +296,7 @@ extern struct mach_port *mach_saved_bootstrap_port;
 /* In-kernel Mach port right description */
 struct mach_right {
 	mach_port_t mr_name;		/* The right name */
-	struct lwp *mr_lwp;		/* points back to struct lwp */
+	struct thread *mr_lwp;		/* points back to struct thread */
 	int mr_type;			/* right type (recv, send, sendonce) */
 	LIST_ENTRY(mach_right) mr_list; /* Right list for a process */
 	int mr_refcount;		/* Reference count */
@@ -314,13 +316,13 @@ struct mach_right {
 	struct mach_right *mr_sethead;	/* Points back to right set */
 };
 
-mach_port_t mach_right_newname(struct lwp *, mach_port_t);
+mach_port_t mach_right_newname(struct thread *, mach_port_t);
 struct mach_right *mach_right_get(struct mach_port *,
-    struct lwp *, int, mach_port_t);
+    struct thread *, int, mach_port_t);
 void mach_right_put(struct mach_right *, int);
 void mach_right_put_shlocked(struct mach_right *, int);
 void mach_right_put_exclocked(struct mach_right *, int);
-struct mach_right *mach_right_check(mach_port_t, struct lwp *, int);
+struct mach_right *mach_right_check(mach_port_t, struct thread *, int);
 
 /* In-kernel Mach port description */
 struct mach_port {
@@ -328,7 +330,7 @@ struct mach_port {
 	int mp_count;			/* Count of queued messages */
 	TAILQ_HEAD(mp_msglist,		/* Queue pending messages */
 	    mach_message) mp_msglist;
-	krwlock_t mp_msglock;		/* Lock for the queue */
+	struct rwlock mp_msglock;		/* Lock for the queue */
 	int mp_refcount;		/* Reference count */
 	int mp_flags;			/* Flags, see below */
 	int mp_datatype;		/* Type of field mp_data, see below */
@@ -341,7 +343,7 @@ struct mach_port {
 
 /* mp_datatype for struct mach_port */
 #define	MACH_MP_NONE		0x0	/* No data */
-#define MACH_MP_LWP		0x1	/* (struct lwp *) */
+#define MACH_MP_LWP		0x1	/* (struct thread *) */
 #define MACH_MP_DEVICE_ITERATOR	0x2	/* (struct mach_device_iterator *) */
 #define MACH_MP_IOKIT_DEVCLASS	0x3	/* (struct mach_iokit_devclass *) */
 #define MACH_MP_PROC		0x4	/* (struct proc *) */
@@ -354,7 +356,7 @@ void mach_port_init(void);
 struct mach_port *mach_port_get(void);
 void mach_port_put(struct mach_port *);
 void mach_remove_recvport(struct mach_port *);
-void mach_add_recvport(struct mach_port *, struct lwp *);
+void mach_add_recvport(struct mach_port *, struct thread *);
 int mach_port_check(struct mach_port *);
 #ifdef DEBUG_MACH
 void mach_debug_port(void);
diff --git a/sys/compat/mach/mach_proto.h b/sys/compat/mach/mach_proto.h
new file mode 100644
index 0000000..f19ee38
--- /dev/null
+++ b/sys/compat/mach/mach_proto.h
@@ -0,0 +1,276 @@
+/*
+ * System call prototypes.
+ *
+ * DO NOT EDIT-- this file is automatically generated.
+ * $FreeBSD$
+ * created from	FreeBSD
+ */
+
+#ifndef _MACH_SYSPROTO_H_
+#define	_MACH_SYSPROTO_H_
+
+#include <sys/signal.h>
+#include <sys/acl.h>
+#include <sys/cpuset.h>
+#include <sys/_ffcounter.h>
+#include <sys/_semaphore.h>
+#include <sys/ucontext.h>
+#include <sys/wait.h>
+
+#include <bsm/audit_kevents.h>
+
+struct proc;
+
+struct thread;
+
+#define	PAD_(t)	(sizeof(register_t) <= sizeof(t) ? \
+		0 : sizeof(register_t) - sizeof(t))
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define	PADL_(t)	0
+#define	PADR_(t)	PAD_(t)
+#else
+#define	PADL_(t)	PAD_(t)
+#define	PADR_(t)	0
+#endif
+
+#if defined(_KERNEL_OPT)
+#endif
+struct mach_reply_port_args {
+	register_t dummy;
+};
+struct mach_thread_self_trap_args {
+	register_t dummy;
+};
+struct mach_task_self_trap_args {
+	register_t dummy;
+};
+struct mach_host_self_trap_args {
+	register_t dummy;
+};
+struct mach_msg_trap_args {
+	char msg_l_[PADL_(mach_msg_header_t *)]; mach_msg_header_t * msg; char msg_r_[PADR_(mach_msg_header_t *)];
+	char option_l_[PADL_(mach_msg_option_t)]; mach_msg_option_t option; char option_r_[PADR_(mach_msg_option_t)];
+	char send_size_l_[PADL_(mach_msg_size_t)]; mach_msg_size_t send_size; char send_size_r_[PADR_(mach_msg_size_t)];
+	char rcv_size_l_[PADL_(mach_msg_size_t)]; mach_msg_size_t rcv_size; char rcv_size_r_[PADR_(mach_msg_size_t)];
+	char rcv_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t rcv_name; char rcv_name_r_[PADR_(mach_port_name_t)];
+	char timeout_l_[PADL_(mach_msg_timeout_t)]; mach_msg_timeout_t timeout; char timeout_r_[PADR_(mach_msg_timeout_t)];
+	char notify_l_[PADL_(mach_port_name_t)]; mach_port_name_t notify; char notify_r_[PADR_(mach_port_name_t)];
+};
+struct mach_msg_overwrite_trap_args {
+	char msg_l_[PADL_(mach_msg_header_t *)]; mach_msg_header_t * msg; char msg_r_[PADR_(mach_msg_header_t *)];
+	char option_l_[PADL_(mach_msg_option_t)]; mach_msg_option_t option; char option_r_[PADR_(mach_msg_option_t)];
+	char send_size_l_[PADL_(mach_msg_size_t)]; mach_msg_size_t send_size; char send_size_r_[PADR_(mach_msg_size_t)];
+	char rcv_size_l_[PADL_(mach_msg_size_t)]; mach_msg_size_t rcv_size; char rcv_size_r_[PADR_(mach_msg_size_t)];
+	char rcv_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t rcv_name; char rcv_name_r_[PADR_(mach_port_name_t)];
+	char timeout_l_[PADL_(mach_msg_timeout_t)]; mach_msg_timeout_t timeout; char timeout_r_[PADR_(mach_msg_timeout_t)];
+	char notify_l_[PADL_(mach_port_name_t)]; mach_port_name_t notify; char notify_r_[PADR_(mach_port_name_t)];
+	char rcv_msg_l_[PADL_(mach_msg_header_t *)]; mach_msg_header_t * rcv_msg; char rcv_msg_r_[PADR_(mach_msg_header_t *)];
+	char scatter_list_size_l_[PADL_(mach_msg_size_t)]; mach_msg_size_t scatter_list_size; char scatter_list_size_r_[PADR_(mach_msg_size_t)];
+};
+struct mach_semaphore_signal_trap_args {
+	char signal_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t signal_name; char signal_name_r_[PADR_(mach_port_name_t)];
+};
+struct mach_semaphore_signal_all_trap_args {
+	char signal_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t signal_name; char signal_name_r_[PADR_(mach_port_name_t)];
+};
+struct mach_semaphore_signal_thread_trap_args {
+	char signal_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t signal_name; char signal_name_r_[PADR_(mach_port_name_t)];
+	char thread_l_[PADL_(mach_port_name_t)]; mach_port_name_t thread; char thread_r_[PADR_(mach_port_name_t)];
+};
+struct mach_semaphore_wait_trap_args {
+	char wait_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t wait_name; char wait_name_r_[PADR_(mach_port_name_t)];
+};
+struct mach_semaphore_wait_signal_trap_args {
+	char wait_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t wait_name; char wait_name_r_[PADR_(mach_port_name_t)];
+	char signal_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t signal_name; char signal_name_r_[PADR_(mach_port_name_t)];
+};
+struct mach_semaphore_timedwait_trap_args {
+	char wait_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t wait_name; char wait_name_r_[PADR_(mach_port_name_t)];
+	char sec_l_[PADL_(unsigned int)]; unsigned int sec; char sec_r_[PADR_(unsigned int)];
+	char nsec_l_[PADL_(mach_clock_res_t)]; mach_clock_res_t nsec; char nsec_r_[PADR_(mach_clock_res_t)];
+};
+struct mach_semaphore_timedwait_signal_trap_args {
+	char wait_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t wait_name; char wait_name_r_[PADR_(mach_port_name_t)];
+	char signal_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t signal_name; char signal_name_r_[PADR_(mach_port_name_t)];
+	char sec_l_[PADL_(unsigned int)]; unsigned int sec; char sec_r_[PADR_(unsigned int)];
+	char nsec_l_[PADL_(mach_clock_res_t)]; mach_clock_res_t nsec; char nsec_r_[PADR_(mach_clock_res_t)];
+};
+struct mach_init_process_args {
+	register_t dummy;
+};
+struct mach_map_fd_args {
+	char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
+	char offset_l_[PADL_(mach_vm_offset_t)]; mach_vm_offset_t offset; char offset_r_[PADR_(mach_vm_offset_t)];
+	char va_l_[PADL_(mach_vm_offset_t *)]; mach_vm_offset_t * va; char va_r_[PADR_(mach_vm_offset_t *)];
+	char findspace_l_[PADL_(mach_boolean_t)]; mach_boolean_t findspace; char findspace_r_[PADR_(mach_boolean_t)];
+	char size_l_[PADL_(mach_vm_size_t)]; mach_vm_size_t size; char size_r_[PADR_(mach_vm_size_t)];
+};
+struct mach_task_for_pid_args {
+	char target_tport_l_[PADL_(mach_port_t)]; mach_port_t target_tport; char target_tport_r_[PADR_(mach_port_t)];
+	char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)];
+	char t_l_[PADL_(mach_port_t *)]; mach_port_t * t; char t_r_[PADR_(mach_port_t *)];
+};
+struct mach_pid_for_task_args {
+	char t_l_[PADL_(mach_port_t)]; mach_port_t t; char t_r_[PADR_(mach_port_t)];
+	char x_l_[PADL_(int *)]; int * x; char x_r_[PADR_(int *)];
+};
+struct mach_macx_swapon_args {
+	char name_l_[PADL_(char *)]; char * name; char name_r_[PADR_(char *)];
+	char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
+	char size_l_[PADL_(int)]; int size; char size_r_[PADR_(int)];
+	char priority_l_[PADL_(int)]; int priority; char priority_r_[PADR_(int)];
+};
+struct mach_macx_swapoff_args {
+	char name_l_[PADL_(char *)]; char * name; char name_r_[PADR_(char *)];
+	char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
+};
+struct mach_macx_triggers_args {
+	char hi_water_l_[PADL_(int)]; int hi_water; char hi_water_r_[PADR_(int)];
+	char low_water_l_[PADL_(int)]; int low_water; char low_water_r_[PADR_(int)];
+	char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
+	char alert_port_l_[PADL_(mach_port_t)]; mach_port_t alert_port; char alert_port_r_[PADR_(mach_port_t)];
+};
+struct mach_swtch_pri_args {
+	char pri_l_[PADL_(int)]; int pri; char pri_r_[PADR_(int)];
+};
+struct mach_swtch_args {
+	register_t dummy;
+};
+struct mach_syscall_thread_switch_args {
+	char thread_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t thread_name; char thread_name_r_[PADR_(mach_port_name_t)];
+	char option_l_[PADL_(int)]; int option; char option_r_[PADR_(int)];
+	char option_time_l_[PADL_(mach_msg_timeout_t)]; mach_msg_timeout_t option_time; char option_time_r_[PADR_(mach_msg_timeout_t)];
+};
+struct mach_clock_sleep_trap_args {
+	char clock_name_l_[PADL_(mach_port_name_t)]; mach_port_name_t clock_name; char clock_name_r_[PADR_(mach_port_name_t)];
+	char sleep_type_l_[PADL_(mach_sleep_type_t)]; mach_sleep_type_t sleep_type; char sleep_type_r_[PADR_(mach_sleep_type_t)];
+	char sleep_sec_l_[PADL_(int)]; int sleep_sec; char sleep_sec_r_[PADR_(int)];
+	char sleep_nsec_l_[PADL_(int)]; int sleep_nsec; char sleep_nsec_r_[PADR_(int)];
+	char wakeup_time_l_[PADL_(mach_timespec_t *)]; mach_timespec_t * wakeup_time; char wakeup_time_r_[PADR_(mach_timespec_t *)];
+};
+struct mach_timebase_info_args {
+	char info_l_[PADL_(mach_timebase_info_t)]; mach_timebase_info_t info; char info_r_[PADR_(mach_timebase_info_t)];
+};
+struct mach_wait_until_args {
+	char deadline_l_[PADL_(uint64_t)]; uint64_t deadline; char deadline_r_[PADR_(uint64_t)];
+};
+struct mach_timer_create_args {
+	register_t dummy;
+};
+struct mach_timer_destroy_args {
+	char name_l_[PADL_(mach_port_name_t)]; mach_port_name_t name; char name_r_[PADR_(mach_port_name_t)];
+};
+struct mach_timer_arm_args {
+	char name_l_[PADL_(mach_port_name_t)]; mach_port_name_t name; char name_r_[PADR_(mach_port_name_t)];
+	char expire_time_l_[PADL_(mach_absolute_time_t)]; mach_absolute_time_t expire_time; char expire_time_r_[PADR_(mach_absolute_time_t)];
+};
+struct mach_timer_cancel_args {
+	char name_l_[PADL_(mach_port_name_t)]; mach_port_name_t name; char name_r_[PADR_(mach_port_name_t)];
+	char result_time_l_[PADL_(mach_absolute_time_t *)]; mach_absolute_time_t * result_time; char result_time_r_[PADR_(mach_absolute_time_t *)];
+};
+struct mach_get_time_base_info_args {
+	register_t dummy;
+};
+#if defined(_KERNEL_OPT)
+#endif
+int	sys_mach_reply_port(struct thread *, struct mach_reply_port_args *);
+int	sys_mach_thread_self_trap(struct thread *, struct mach_thread_self_trap_args *);
+int	sys_mach_task_self_trap(struct thread *, struct mach_task_self_trap_args *);
+int	sys_mach_host_self_trap(struct thread *, struct mach_host_self_trap_args *);
+int	sys_mach_msg_trap(struct thread *, struct mach_msg_trap_args *);
+int	sys_mach_msg_overwrite_trap(struct thread *, struct mach_msg_overwrite_trap_args *);
+int	sys_mach_semaphore_signal_trap(struct thread *, struct mach_semaphore_signal_trap_args *);
+int	sys_mach_semaphore_signal_all_trap(struct thread *, struct mach_semaphore_signal_all_trap_args *);
+int	sys_mach_semaphore_signal_thread_trap(struct thread *, struct mach_semaphore_signal_thread_trap_args *);
+int	sys_mach_semaphore_wait_trap(struct thread *, struct mach_semaphore_wait_trap_args *);
+int	sys_mach_semaphore_wait_signal_trap(struct thread *, struct mach_semaphore_wait_signal_trap_args *);
+int	sys_mach_semaphore_timedwait_trap(struct thread *, struct mach_semaphore_timedwait_trap_args *);
+int	sys_mach_semaphore_timedwait_signal_trap(struct thread *, struct mach_semaphore_timedwait_signal_trap_args *);
+int	sys_mach_init_process(struct thread *, struct mach_init_process_args *);
+int	sys_mach_map_fd(struct thread *, struct mach_map_fd_args *);
+int	sys_mach_task_for_pid(struct thread *, struct mach_task_for_pid_args *);
+int	sys_mach_pid_for_task(struct thread *, struct mach_pid_for_task_args *);
+int	sys_mach_macx_swapon(struct thread *, struct mach_macx_swapon_args *);
+int	sys_mach_macx_swapoff(struct thread *, struct mach_macx_swapoff_args *);
+int	sys_mach_macx_triggers(struct thread *, struct mach_macx_triggers_args *);
+int	sys_mach_swtch_pri(struct thread *, struct mach_swtch_pri_args *);
+int	sys_mach_swtch(struct thread *, struct mach_swtch_args *);
+int	sys_mach_syscall_thread_switch(struct thread *, struct mach_syscall_thread_switch_args *);
+int	sys_mach_clock_sleep_trap(struct thread *, struct mach_clock_sleep_trap_args *);
+int	sys_mach_timebase_info(struct thread *, struct mach_timebase_info_args *);
+int	sys_mach_wait_until(struct thread *, struct mach_wait_until_args *);
+int	sys_mach_timer_create(struct thread *, struct mach_timer_create_args *);
+int	sys_mach_timer_destroy(struct thread *, struct mach_timer_destroy_args *);
+int	sys_mach_timer_arm(struct thread *, struct mach_timer_arm_args *);
+int	sys_mach_timer_cancel(struct thread *, struct mach_timer_cancel_args *);
+int	sys_mach_get_time_base_info(struct thread *, struct mach_get_time_base_info_args *);
+
+#ifdef COMPAT_43
+
+#if defined(_KERNEL_OPT)
+#endif
+
+#endif /* COMPAT_43 */
+
+
+#ifdef COMPAT_FREEBSD4
+
+#if defined(_KERNEL_OPT)
+#endif
+
+#endif /* COMPAT_FREEBSD4 */
+
+
+#ifdef COMPAT_FREEBSD6
+
+#if defined(_KERNEL_OPT)
+#endif
+
+#endif /* COMPAT_FREEBSD6 */
+
+
+#ifdef COMPAT_FREEBSD7
+
+#if defined(_KERNEL_OPT)
+#endif
+
+#endif /* COMPAT_FREEBSD7 */
+
+#define	MACH_SYS_AUE_mach_reply_port	AUE_NULL
+#define	MACH_SYS_AUE_mach_thread_self_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_task_self_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_host_self_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_msg_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_msg_overwrite_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_semaphore_signal_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_semaphore_signal_all_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_semaphore_signal_thread_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_semaphore_wait_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_semaphore_wait_signal_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_semaphore_timedwait_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_semaphore_timedwait_signal_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_init_process	AUE_NULL
+#define	MACH_SYS_AUE_mach_map_fd	AUE_NULL
+#define	MACH_SYS_AUE_mach_task_for_pid	AUE_NULL
+#define	MACH_SYS_AUE_mach_pid_for_task	AUE_NULL
+#define	MACH_SYS_AUE_mach_macx_swapon	AUE_NULL
+#define	MACH_SYS_AUE_mach_macx_swapoff	AUE_NULL
+#define	MACH_SYS_AUE_mach_macx_triggers	AUE_NULL
+#define	MACH_SYS_AUE_mach_swtch_pri	AUE_NULL
+#define	MACH_SYS_AUE_mach_swtch	AUE_NULL
+#define	MACH_SYS_AUE_mach_syscall_thread_switch	AUE_NULL
+#define	MACH_SYS_AUE_mach_clock_sleep_trap	AUE_NULL
+#define	MACH_SYS_AUE_mach_timebase_info	AUE_NULL
+#define	MACH_SYS_AUE_mach_wait_until	AUE_NULL
+#define	MACH_SYS_AUE_mach_timer_create	AUE_NULL
+#define	MACH_SYS_AUE_mach_timer_destroy	AUE_NULL
+#define	MACH_SYS_AUE_mach_timer_arm	AUE_NULL
+#define	MACH_SYS_AUE_mach_timer_cancel	AUE_NULL
+#define	MACH_SYS_AUE_mach_get_time_base_info	AUE_NULL
+
+#undef PAD_
+#undef PADL_
+#undef PADR_
+
+#endif /* !_MACH_SYSPROTO_H_ */
diff --git a/sys/compat/mach/mach_semaphore.c b/sys/compat/mach/mach_semaphore.c
index 327c893..6953b1a 100644
--- a/sys/compat/mach/mach_semaphore.c
+++ b/sys/compat/mach/mach_semaphore.c
@@ -1,5 +1,3 @@
-/*	$NetBSD: mach_semaphore.c,v 1.19 2008/04/28 20:23:44 martin Exp $ */
-
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,16 +28,17 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_semaphore.c,v 1.19 2008/04/28 20:23:44 martin Exp $");
+__FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/signal.h>
-#include <sys/pool.h>
-#include <sys/rwlock.h>
+#include <sys/lock.h>
 #include <sys/malloc.h>
+#include <sys/pool.h>
 #include <sys/proc.h>
+#include <sys/rwlock.h>
 
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
@@ -48,7 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: mach_semaphore.c,v 1.19 2008/04/28 20:23:44 martin E
 #include <compat/mach/mach_errno.h>
 #include <compat/mach/mach_port.h>
 #include <compat/mach/mach_services.h>
-#include <compat/mach/mach_syscallargs.h>
+#include <compat/mach/mach_proto.h>
 
 /* Semaphore list, lock, pools */
 static LIST_HEAD(mach_semaphore_list, mach_semaphore) mach_semaphore_list;
@@ -65,7 +64,7 @@ static void mach_waiting_lwp_put
     (struct mach_waiting_lwp *, struct mach_semaphore *, int);
 
 int
-mach_sys_semaphore_wait_trap(struct lwp *l, const struct mach_sys_semaphore_wait_trap_args *uap, register_t *retval)
+mach_sys_semaphore_wait_trap(struct thread *td, struct mach_sys_semaphore_wait_trap_args *uap)
 {
 	/* {
 		syscallarg(mach_port_name_t) wait_name;
@@ -76,8 +75,8 @@ mach_sys_semaphore_wait_trap(struct lwp *l, const struct mach_sys_semaphore_wait
 	mach_port_t mn;
 	int blocked = 0;
 
-	mn = SCARG(uap, wait_name);
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == 0)
+	mn = uap->wait_name);
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == 0)
 		return EPERM;
 
 	if (mr->mr_port->mp_datatype != MACH_MP_SEMAPHORE)
@@ -101,7 +100,7 @@ mach_sys_semaphore_wait_trap(struct lwp *l, const struct mach_sys_semaphore_wait
 }
 
 int
-mach_sys_semaphore_signal_trap(struct lwp *l, const struct mach_sys_semaphore_signal_trap_args *uap, register_t *retval)
+mach_sys_semaphore_signal_trap(struct thread *td, struct mach_sys_semaphore_signal_trap_args *uap)
 {
 	/* {
 		syscallarg(mach_port_name_t) signal_name;
@@ -112,8 +111,8 @@ mach_sys_semaphore_signal_trap(struct lwp *l, const struct mach_sys_semaphore_si
 	mach_port_t mn;
 	int unblocked = 0;
 
-	mn = SCARG(uap, signal_name);
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == 0)
+	mn = uap->signal_name);
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == 0)
 		return EPERM;
 
 	if (mr->mr_port->mp_datatype != MACH_MP_SEMAPHORE)
@@ -142,7 +141,7 @@ mach_semaphore_create(struct mach_trap_args *args)
 	mach_semaphore_create_request_t *req = args->smsg;
 	mach_semaphore_create_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	struct mach_semaphore *ms;
 	struct mach_port *mp;
 	struct mach_right *mr;
@@ -153,7 +152,7 @@ mach_semaphore_create(struct mach_trap_args *args)
 	mp->mp_datatype = MACH_MP_SEMAPHORE;
 	mp->mp_data = (void *)ms;
 
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
@@ -168,14 +167,14 @@ mach_semaphore_destroy(struct mach_trap_args *args)
 {
 	mach_semaphore_destroy_request_t *req = args->smsg;
 	mach_semaphore_destroy_reply_t *rep = args->rmsg;
-	struct lwp *l = args->l;
+	struct thread *td = args->td;
 	size_t *msglen = args->rsize;
 	struct mach_semaphore *ms;
 	struct mach_right *mr;
 	mach_port_t mn;
 
 	mn = req->req_sem.name;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == 0)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == 0)
 		return mach_msg_error(args, EPERM);
 
 	if (mr->mr_port->mp_datatype != MACH_MP_SEMAPHORE)
@@ -248,7 +247,7 @@ mach_semaphore_put(struct mach_semaphore *ms)
 }
 
 static struct mach_waiting_lwp *
-mach_waiting_lwp_get(struct lwp *l, struct mach_semaphore *ms)
+mach_waiting_lwp_get(struct thread *td, struct mach_semaphore *ms)
 {
 	struct mach_waiting_lwp *mwl;
 
@@ -281,7 +280,7 @@ mach_waiting_lwp_put(struct mach_waiting_lwp *mwl, struct mach_semaphore *ms, in
  * can be some memory leaks here.
  */
 void
-mach_semaphore_cleanup(struct lwp *l)
+mach_semaphore_cleanup(struct thread *td)
 {
 	struct mach_semaphore *ms;
 	struct mach_waiting_lwp *mwl;
@@ -304,7 +303,7 @@ mach_semaphore_cleanup(struct lwp *l)
 }
 
 int
-mach_sys_semaphore_wait_signal_trap(struct lwp *l, const struct mach_sys_semaphore_wait_signal_trap_args *uap, register_t *retval)
+mach_sys_semaphore_wait_signal_trap(struct thread *td, struct mach_sys_semaphore_wait_signal_trap_args *uap)
 {
 	/* {
 		syscallarg(mach_port_name_t) wait_name;
@@ -314,12 +313,12 @@ mach_sys_semaphore_wait_signal_trap(struct lwp *l, const struct mach_sys_semapho
 	struct mach_sys_semaphore_signal_trap_args cupsig;
 	int error;
 
-	SCARG(&cupsig, signal_name) = SCARG(uap, signal_name);
-	if ((error = mach_sys_semaphore_signal_trap(l, &cupsig, retval)) != 0)
+	&cupsig->signal_name = uap->signal_name;
+	if ((error = mach_sys_semaphore_signal_trap(td, &cupsig)) != 0)
 		return error;
 
-	SCARG(&cupwait, wait_name) = SCARG(uap, wait_name);
-	if ((error = mach_sys_semaphore_wait_trap(l, &cupwait, retval)) != 0)
+	&cupwait->wait_name = uap->wait_name;
+	if ((error = mach_sys_semaphore_wait_trap(td, &cupwait)) != 0)
 		return error;
 
 	return 0;
@@ -327,7 +326,7 @@ mach_sys_semaphore_wait_signal_trap(struct lwp *l, const struct mach_sys_semapho
 
 
 int
-mach_sys_semaphore_signal_thread_trap(struct lwp *l, const struct mach_sys_semaphore_signal_thread_trap_args *uap, register_t *retval)
+mach_sys_semaphore_signal_thread_trap(struct thread *td, struct mach_sys_semaphore_signal_thread_trap_args *uap)
 {
 	/* {
 		syscallarg(mach_port_name_t) signal_name;
@@ -342,8 +341,8 @@ mach_sys_semaphore_signal_thread_trap(struct lwp *l, const struct mach_sys_semap
 	/*
 	 * Get the semaphore
 	 */
-	mn = SCARG(uap, signal_name);
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	mn = uap->signal_name);
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return EINVAL;
 
 	if (mr->mr_port->mp_datatype != MACH_MP_SEMAPHORE)
@@ -355,9 +354,9 @@ mach_sys_semaphore_signal_thread_trap(struct lwp *l, const struct mach_sys_semap
 	 * Get the thread, and check that it is waiting for our semaphore
 	 * If no thread was supplied, pick up the first one.
 	 */
-	mn = SCARG(uap, thread);
+	mn = uap->thread);
 	if (mn != 0) {
-		if ((mr = mach_right_check(mn, l,
+		if ((mr = mach_right_check(mn, td,
 		    MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 			return EINVAL;
 
@@ -395,7 +394,7 @@ mach_sys_semaphore_signal_thread_trap(struct lwp *l, const struct mach_sys_semap
 
 
 int
-mach_sys_semaphore_signal_all_trap(struct lwp *l, const struct mach_sys_semaphore_signal_all_trap_args *uap, register_t *retval)
+mach_sys_semaphore_signal_all_trap(struct thread *td, struct mach_sys_semaphore_signal_all_trap_args *uap)
 {
 	/* {
 		syscallarg(mach_port_name_t) signal_name;
@@ -409,8 +408,8 @@ mach_sys_semaphore_signal_all_trap(struct lwp *l, const struct mach_sys_semaphor
 	/*
 	 * Get the semaphore
 	 */
-	mn = SCARG(uap, signal_name);
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	mn = uap->signal_name;
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return EINVAL;
 
 	if (mr->mr_port->mp_datatype != MACH_MP_SEMAPHORE)
diff --git a/sys/compat/mach/mach_semaphore.h b/sys/compat/mach/mach_semaphore.h
index 337ca3e..26b259f 100644
--- a/sys/compat/mach/mach_semaphore.h
+++ b/sys/compat/mach/mach_semaphore.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_semaphore.h,v 1.7 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -32,6 +32,7 @@
 #ifndef	_MACH_SEMAPHORE_H_
 #define	_MACH_SEMAPHORE_H_
 
+#include <sys/lock.h>
 #include <sys/rwlock.h>
 #include <sys/queue.h>
 
@@ -47,7 +48,7 @@ struct mach_semaphore {
 	int ms_policy;
 	LIST_ENTRY(mach_semaphore) ms_list;
 	TAILQ_HEAD(ms_waiting, mach_waiting_lwp) ms_waiting;
-	krwlock_t ms_lock;
+	struct rwlock ms_lock;
 };
 
 /* semaphore_create */
diff --git a/sys/compat/mach/mach_services.c b/sys/compat/mach/mach_services.c
index bf10124..2ce0fd1 100644
--- a/sys/compat/mach/mach_services.c
+++ b/sys/compat/mach/mach_services.c
@@ -8,7 +8,6 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_services.c,v 1.19 2009/01/13 22:33:10 pooka Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
diff --git a/sys/compat/mach/mach_services.h b/sys/compat/mach/mach_services.h
index 4894a3a..49ed48b 100644
--- a/sys/compat/mach/mach_services.h
+++ b/sys/compat/mach/mach_services.h
@@ -8,7 +8,6 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_services.h,v 1.19 2009/01/13 22:33:10 pooka Exp $");
 
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
diff --git a/sys/compat/mach/mach_services_names.c b/sys/compat/mach/mach_services_names.c
index dd0a3c7..877e637 100644
--- a/sys/compat/mach/mach_services_names.c
+++ b/sys/compat/mach/mach_services_names.c
@@ -9,7 +9,6 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_services_names.c,v 1.16 2009/01/13 22:33:10 pooka Exp $");
 
 struct mach_service_name {
 	int srv_id;
diff --git a/sys/compat/mach/mach_syscall.h b/sys/compat/mach/mach_syscall.h
index cbab9dc..7f625ee 100644
--- a/sys/compat/mach/mach_syscall.h
+++ b/sys/compat/mach/mach_syscall.h
@@ -1,110 +1,40 @@
-/* $NetBSD: mach_syscall.h,v 1.21 2009/12/14 00:58:37 matt Exp $ */
-
 /*
  * System call numbers.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.10 2009/01/13 22:27:43 pooka Exp
+ * $FreeBSD$
+ * created from	FreeBSD
  */
 
-#ifndef _MACH_SYS_SYSCALL_H_
-#define	_MACH_SYS_SYSCALL_H_
-
-#define	MACH_SYS_MAXSYSARGS	9
-
-/* syscall: "reply_port" ret: "mach_port_name_t" args: */
-#define	MACH_SYS_reply_port	26
-
-/* syscall: "thread_self_trap" ret: "mach_port_name_t" args: */
-#define	MACH_SYS_thread_self_trap	27
-
-/* syscall: "task_self_trap" ret: "mach_port_name_t" args: */
-#define	MACH_SYS_task_self_trap	28
-
-/* syscall: "host_self_trap" ret: "mach_port_name_t" args: */
-#define	MACH_SYS_host_self_trap	29
-
-/* syscall: "msg_trap" ret: "mach_msg_return_t" args: "mach_msg_header_t *" "mach_msg_option_t" "mach_msg_size_t" "mach_msg_size_t" "mach_port_name_t" "mach_msg_timeout_t" "mach_port_name_t" */
-#define	MACH_SYS_msg_trap	31
-
-/* syscall: "msg_overwrite_trap" ret: "mach_kern_return_t" args: "mach_msg_header_t *" "mach_msg_option_t" "mach_msg_size_t" "mach_msg_size_t" "mach_port_name_t" "mach_msg_timeout_t" "mach_port_name_t" "mach_msg_header_t *" "mach_msg_size_t" */
-#define	MACH_SYS_msg_overwrite_trap	32
-
-/* syscall: "semaphore_signal_trap" ret: "mach_kern_return_t" args: "mach_port_name_t" */
-#define	MACH_SYS_semaphore_signal_trap	33
-
-/* syscall: "semaphore_signal_all_trap" ret: "mach_kern_return_t" args: "mach_port_name_t" */
-#define	MACH_SYS_semaphore_signal_all_trap	34
-
-/* syscall: "semaphore_signal_thread_trap" ret: "mach_kern_return_t" args: "mach_port_name_t" "mach_port_name_t" */
-#define	MACH_SYS_semaphore_signal_thread_trap	35
-
-/* syscall: "semaphore_wait_trap" ret: "mach_kern_return_t" args: "mach_port_name_t" */
-#define	MACH_SYS_semaphore_wait_trap	36
-
-/* syscall: "semaphore_wait_signal_trap" ret: "mach_kern_return_t" args: "mach_port_name_t" "mach_port_name_t" */
-#define	MACH_SYS_semaphore_wait_signal_trap	37
-
-/* syscall: "semaphore_timedwait_trap" ret: "mach_kern_return_t" args: "mach_port_name_t" "unsigned int" "mach_clock_res_t" */
-#define	MACH_SYS_semaphore_timedwait_trap	38
-
-/* syscall: "semaphore_timedwait_signal_trap" ret: "mach_kern_return_t" args: "mach_port_name_t" "mach_port_name_t" "unsigned int" "mach_clock_res_t" */
-#define	MACH_SYS_semaphore_timedwait_signal_trap	39
-
-/* syscall: "init_process" ret: "mach_kern_return_t" args: */
-#define	MACH_SYS_init_process	41
-
-/* syscall: "map_fd" ret: "mach_kern_return_t" args: "int" "mach_vm_offset_t" "mach_vm_offset_t *" "mach_boolean_t" "mach_vm_size_t" */
-#define	MACH_SYS_map_fd	43
-
-/* syscall: "task_for_pid" ret: "mach_kern_return_t" args: "mach_port_t" "int" "mach_port_t *" */
-#define	MACH_SYS_task_for_pid	45
-
-/* syscall: "pid_for_task" ret: "mach_kern_return_t" args: "mach_port_t" "int *" */
-#define	MACH_SYS_pid_for_task	46
-
-/* syscall: "macx_swapon" ret: "mach_kern_return_t" args: "char *" "int" "int" "int" */
-#define	MACH_SYS_macx_swapon	48
-
-/* syscall: "macx_swapoff" ret: "mach_kern_return_t" args: "char *" "int" */
-#define	MACH_SYS_macx_swapoff	49
-
-/* syscall: "macx_triggers" ret: "mach_kern_return_t" args: "int" "int" "int" "mach_port_t" */
-#define	MACH_SYS_macx_triggers	51
-
-/* syscall: "swtch_pri" ret: "mach_kern_return_t" args: "int" */
-#define	MACH_SYS_swtch_pri	59
-
-/* syscall: "swtch" ret: "mach_kern_return_t" args: */
-#define	MACH_SYS_swtch	60
-
-/* syscall: "syscall_thread_switch" ret: "mach_kern_return_t" args: "mach_port_name_t" "int" "mach_msg_timeout_t" */
-#define	MACH_SYS_syscall_thread_switch	61
-
-/* syscall: "clock_sleep_trap" ret: "mach_kern_return_t" args: "mach_port_name_t" "mach_sleep_type_t" "int" "int" "mach_timespec_t *" */
-#define	MACH_SYS_clock_sleep_trap	62
-
-/* syscall: "timebase_info" ret: "mach_kern_return_t" args: "mach_timebase_info_t" */
-#define	MACH_SYS_timebase_info	89
-
-/* syscall: "wait_until" ret: "mach_kern_return_t" args: "u_int64_t" */
-#define	MACH_SYS_wait_until	90
-
-/* syscall: "timer_create" ret: "mach_port_name_t" args: */
-#define	MACH_SYS_timer_create	91
-
-/* syscall: "timer_destroy" ret: "mach_kern_return_t" args: "mach_port_name_t" */
-#define	MACH_SYS_timer_destroy	92
-
-/* syscall: "timer_arm" ret: "mach_kern_return_t" args: "mach_port_name_t" "mach_absolute_time_t" */
-#define	MACH_SYS_timer_arm	93
-
-/* syscall: "timer_cancel" ret: "mach_kern_return_t" args: "mach_port_name_t" "mach_absolute_time_t *" */
-#define	MACH_SYS_timer_cancel	94
-
-/* syscall: "get_time_base_info" ret: "mach_kern_return_t" args: */
-#define	MACH_SYS_get_time_base_info	95
-
+#define	MACH_SYS_mach_reply_port	26
+#define	MACH_SYS_mach_thread_self_trap	27
+#define	MACH_SYS_mach_task_self_trap	28
+#define	MACH_SYS_mach_host_self_trap	29
+#define	MACH_SYS_mach_msg_trap	31
+#define	MACH_SYS_mach_msg_overwrite_trap	32
+#define	MACH_SYS_mach_semaphore_signal_trap	33
+#define	MACH_SYS_mach_semaphore_signal_all_trap	34
+#define	MACH_SYS_mach_semaphore_signal_thread_trap	35
+#define	MACH_SYS_mach_semaphore_wait_trap	36
+#define	MACH_SYS_mach_semaphore_wait_signal_trap	37
+#define	MACH_SYS_mach_semaphore_timedwait_trap	38
+#define	MACH_SYS_mach_semaphore_timedwait_signal_trap	39
+#define	MACH_SYS_mach_init_process	41
+#define	MACH_SYS_mach_map_fd	43
+#define	MACH_SYS_mach_task_for_pid	45
+#define	MACH_SYS_mach_pid_for_task	46
+#define	MACH_SYS_mach_macx_swapon	48
+#define	MACH_SYS_mach_macx_swapoff	49
+#define	MACH_SYS_mach_macx_triggers	51
+#define	MACH_SYS_mach_swtch_pri	59
+#define	MACH_SYS_mach_swtch	60
+#define	MACH_SYS_mach_syscall_thread_switch	61
+#define	MACH_SYS_mach_clock_sleep_trap	62
+#define	MACH_SYS_mach_timebase_info	89
+#define	MACH_SYS_mach_wait_until	90
+#define	MACH_SYS_mach_timer_create	91
+#define	MACH_SYS_mach_timer_destroy	92
+#define	MACH_SYS_mach_timer_arm	93
+#define	MACH_SYS_mach_timer_cancel	94
+#define	MACH_SYS_mach_get_time_base_info	95
 #define	MACH_SYS_MAXSYSCALL	128
-#define	MACH_SYS_NSYSENT	128
-#endif /* _MACH_SYS_SYSCALL_H_ */
diff --git a/sys/compat/mach/mach_syscallargs.h b/sys/compat/mach/mach_syscallargs.h
deleted file mode 100644
index 4361eb2..0000000
--- a/sys/compat/mach/mach_syscallargs.h
+++ /dev/null
@@ -1,258 +0,0 @@
-/* $NetBSD: mach_syscallargs.h,v 1.21 2009/12/14 00:58:37 matt Exp $ */
-
-/*
- * System call argument lists.
- *
- * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.10 2009/01/13 22:27:43 pooka Exp
- */
-
-#ifndef _MACH_SYS_SYSCALLARGS_H_
-#define	_MACH_SYS_SYSCALLARGS_H_
-
-#define	MACH_SYS_MAXSYSARGS	9
-
-#undef	syscallarg
-#define	syscallarg(x)							\
-	union {								\
-		register_t pad;						\
-		struct { x datum; } le;					\
-		struct { /* LINTED zero array dimension */		\
-			int8_t pad[  /* CONSTCOND */			\
-				(sizeof (register_t) < sizeof (x))	\
-				? 0					\
-				: sizeof (register_t) - sizeof (x)];	\
-			x datum;					\
-		} be;							\
-	}
-
-#undef check_syscall_args
-#define check_syscall_args(call) \
-	typedef char call##_check_args[sizeof (struct call##_args) \
-		<= MACH_SYS_MAXSYSARGS * sizeof (register_t) ? 1 : -1];
-
-struct mach_sys_msg_trap_args {
-	syscallarg(mach_msg_header_t *) msg;
-	syscallarg(mach_msg_option_t) option;
-	syscallarg(mach_msg_size_t) send_size;
-	syscallarg(mach_msg_size_t) rcv_size;
-	syscallarg(mach_port_name_t) rcv_name;
-	syscallarg(mach_msg_timeout_t) timeout;
-	syscallarg(mach_port_name_t) notify;
-};
-check_syscall_args(mach_sys_msg_trap)
-
-struct mach_sys_msg_overwrite_trap_args {
-	syscallarg(mach_msg_header_t *) msg;
-	syscallarg(mach_msg_option_t) option;
-	syscallarg(mach_msg_size_t) send_size;
-	syscallarg(mach_msg_size_t) rcv_size;
-	syscallarg(mach_port_name_t) rcv_name;
-	syscallarg(mach_msg_timeout_t) timeout;
-	syscallarg(mach_port_name_t) notify;
-	syscallarg(mach_msg_header_t *) rcv_msg;
-	syscallarg(mach_msg_size_t) scatter_list_size;
-};
-check_syscall_args(mach_sys_msg_overwrite_trap)
-
-struct mach_sys_semaphore_signal_trap_args {
-	syscallarg(mach_port_name_t) signal_name;
-};
-check_syscall_args(mach_sys_semaphore_signal_trap)
-
-struct mach_sys_semaphore_signal_all_trap_args {
-	syscallarg(mach_port_name_t) signal_name;
-};
-check_syscall_args(mach_sys_semaphore_signal_all_trap)
-
-struct mach_sys_semaphore_signal_thread_trap_args {
-	syscallarg(mach_port_name_t) signal_name;
-	syscallarg(mach_port_name_t) thread;
-};
-check_syscall_args(mach_sys_semaphore_signal_thread_trap)
-
-struct mach_sys_semaphore_wait_trap_args {
-	syscallarg(mach_port_name_t) wait_name;
-};
-check_syscall_args(mach_sys_semaphore_wait_trap)
-
-struct mach_sys_semaphore_wait_signal_trap_args {
-	syscallarg(mach_port_name_t) wait_name;
-	syscallarg(mach_port_name_t) signal_name;
-};
-check_syscall_args(mach_sys_semaphore_wait_signal_trap)
-
-struct mach_sys_semaphore_timedwait_trap_args {
-	syscallarg(mach_port_name_t) wait_name;
-	syscallarg(unsigned int) sec;
-	syscallarg(mach_clock_res_t) nsec;
-};
-check_syscall_args(mach_sys_semaphore_timedwait_trap)
-
-struct mach_sys_semaphore_timedwait_signal_trap_args {
-	syscallarg(mach_port_name_t) wait_name;
-	syscallarg(mach_port_name_t) signal_name;
-	syscallarg(unsigned int) sec;
-	syscallarg(mach_clock_res_t) nsec;
-};
-check_syscall_args(mach_sys_semaphore_timedwait_signal_trap)
-
-struct mach_sys_map_fd_args {
-	syscallarg(int) fd;
-	syscallarg(mach_vm_offset_t) offset;
-	syscallarg(mach_vm_offset_t *) va;
-	syscallarg(mach_boolean_t) findspace;
-	syscallarg(mach_vm_size_t) size;
-};
-check_syscall_args(mach_sys_map_fd)
-
-struct mach_sys_task_for_pid_args {
-	syscallarg(mach_port_t) target_tport;
-	syscallarg(int) pid;
-	syscallarg(mach_port_t *) t;
-};
-check_syscall_args(mach_sys_task_for_pid)
-
-struct mach_sys_pid_for_task_args {
-	syscallarg(mach_port_t) t;
-	syscallarg(int *) x;
-};
-check_syscall_args(mach_sys_pid_for_task)
-
-struct mach_sys_macx_swapon_args {
-	syscallarg(char *) name;
-	syscallarg(int) flags;
-	syscallarg(int) size;
-	syscallarg(int) priority;
-};
-check_syscall_args(mach_sys_macx_swapon)
-
-struct mach_sys_macx_swapoff_args {
-	syscallarg(char *) name;
-	syscallarg(int) flags;
-};
-check_syscall_args(mach_sys_macx_swapoff)
-
-struct mach_sys_macx_triggers_args {
-	syscallarg(int) hi_water;
-	syscallarg(int) low_water;
-	syscallarg(int) flags;
-	syscallarg(mach_port_t) alert_port;
-};
-check_syscall_args(mach_sys_macx_triggers)
-
-struct mach_sys_swtch_pri_args {
-	syscallarg(int) pri;
-};
-check_syscall_args(mach_sys_swtch_pri)
-
-struct mach_sys_syscall_thread_switch_args {
-	syscallarg(mach_port_name_t) thread_name;
-	syscallarg(int) option;
-	syscallarg(mach_msg_timeout_t) option_time;
-};
-check_syscall_args(mach_sys_syscall_thread_switch)
-
-struct mach_sys_clock_sleep_trap_args {
-	syscallarg(mach_port_name_t) clock_name;
-	syscallarg(mach_sleep_type_t) sleep_type;
-	syscallarg(int) sleep_sec;
-	syscallarg(int) sleep_nsec;
-	syscallarg(mach_timespec_t *) wakeup_time;
-};
-check_syscall_args(mach_sys_clock_sleep_trap)
-
-struct mach_sys_timebase_info_args {
-	syscallarg(mach_timebase_info_t) info;
-};
-check_syscall_args(mach_sys_timebase_info)
-
-struct mach_sys_wait_until_args {
-	syscallarg(u_int64_t) deadline;
-};
-check_syscall_args(mach_sys_wait_until)
-
-struct mach_sys_timer_destroy_args {
-	syscallarg(mach_port_name_t) name;
-};
-check_syscall_args(mach_sys_timer_destroy)
-
-struct mach_sys_timer_arm_args {
-	syscallarg(mach_port_name_t) name;
-	syscallarg(mach_absolute_time_t) expire_time;
-};
-check_syscall_args(mach_sys_timer_arm)
-
-struct mach_sys_timer_cancel_args {
-	syscallarg(mach_port_name_t) name;
-	syscallarg(mach_absolute_time_t *) result_time;
-};
-check_syscall_args(mach_sys_timer_cancel)
-
-/*
- * System call prototypes.
- */
-
-int	mach_sys_reply_port(struct lwp *, const void *, register_t *);
-
-int	mach_sys_thread_self_trap(struct lwp *, const void *, register_t *);
-
-int	mach_sys_task_self_trap(struct lwp *, const void *, register_t *);
-
-int	mach_sys_host_self_trap(struct lwp *, const void *, register_t *);
-
-int	mach_sys_msg_trap(struct lwp *, const struct mach_sys_msg_trap_args *, register_t *);
-
-int	mach_sys_msg_overwrite_trap(struct lwp *, const struct mach_sys_msg_overwrite_trap_args *, register_t *);
-
-int	mach_sys_semaphore_signal_trap(struct lwp *, const struct mach_sys_semaphore_signal_trap_args *, register_t *);
-
-int	mach_sys_semaphore_signal_all_trap(struct lwp *, const struct mach_sys_semaphore_signal_all_trap_args *, register_t *);
-
-int	mach_sys_semaphore_signal_thread_trap(struct lwp *, const struct mach_sys_semaphore_signal_thread_trap_args *, register_t *);
-
-int	mach_sys_semaphore_wait_trap(struct lwp *, const struct mach_sys_semaphore_wait_trap_args *, register_t *);
-
-int	mach_sys_semaphore_wait_signal_trap(struct lwp *, const struct mach_sys_semaphore_wait_signal_trap_args *, register_t *);
-
-int	mach_sys_semaphore_timedwait_trap(struct lwp *, const struct mach_sys_semaphore_timedwait_trap_args *, register_t *);
-
-int	mach_sys_semaphore_timedwait_signal_trap(struct lwp *, const struct mach_sys_semaphore_timedwait_signal_trap_args *, register_t *);
-
-int	mach_sys_init_process(struct lwp *, const void *, register_t *);
-
-int	mach_sys_map_fd(struct lwp *, const struct mach_sys_map_fd_args *, register_t *);
-
-int	mach_sys_task_for_pid(struct lwp *, const struct mach_sys_task_for_pid_args *, register_t *);
-
-int	mach_sys_pid_for_task(struct lwp *, const struct mach_sys_pid_for_task_args *, register_t *);
-
-int	mach_sys_macx_swapon(struct lwp *, const struct mach_sys_macx_swapon_args *, register_t *);
-
-int	mach_sys_macx_swapoff(struct lwp *, const struct mach_sys_macx_swapoff_args *, register_t *);
-
-int	mach_sys_macx_triggers(struct lwp *, const struct mach_sys_macx_triggers_args *, register_t *);
-
-int	mach_sys_swtch_pri(struct lwp *, const struct mach_sys_swtch_pri_args *, register_t *);
-
-int	mach_sys_swtch(struct lwp *, const void *, register_t *);
-
-int	mach_sys_syscall_thread_switch(struct lwp *, const struct mach_sys_syscall_thread_switch_args *, register_t *);
-
-int	mach_sys_clock_sleep_trap(struct lwp *, const struct mach_sys_clock_sleep_trap_args *, register_t *);
-
-int	mach_sys_timebase_info(struct lwp *, const struct mach_sys_timebase_info_args *, register_t *);
-
-int	mach_sys_wait_until(struct lwp *, const struct mach_sys_wait_until_args *, register_t *);
-
-int	mach_sys_timer_create(struct lwp *, const void *, register_t *);
-
-int	mach_sys_timer_destroy(struct lwp *, const struct mach_sys_timer_destroy_args *, register_t *);
-
-int	mach_sys_timer_arm(struct lwp *, const struct mach_sys_timer_arm_args *, register_t *);
-
-int	mach_sys_timer_cancel(struct lwp *, const struct mach_sys_timer_cancel_args *, register_t *);
-
-int	mach_sys_get_time_base_info(struct lwp *, const void *, register_t *);
-
-#endif /* _MACH_SYS_SYSCALLARGS_H_ */
diff --git a/sys/compat/mach/mach_syscalls.c b/sys/compat/mach/mach_syscalls.c
index f8f7d7b..76aa670 100644
--- a/sys/compat/mach/mach_syscalls.c
+++ b/sys/compat/mach/mach_syscalls.c
@@ -1,159 +1,140 @@
-/* $NetBSD: mach_syscalls.c,v 1.22 2009/12/14 00:58:37 matt Exp $ */
-
 /*
  * System call names.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.10 2009/01/13 22:27:43 pooka Exp
+ * $FreeBSD$
+ * created from	FreeBSD
  */
 
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_syscalls.c,v 1.22 2009/12/14 00:58:37 matt Exp $");
-
+const char *mach_syscallnames[] = {
 #if defined(_KERNEL_OPT)
-#if defined(_KERNEL_OPT)
-#include "opt_ntp.h"
-#include "opt_sysv.h"
 #endif
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/signal.h>
-#include <sys/mount.h>
-#include <sys/poll.h>
-#include <sys/syscallargs.h>
-#include <compat/mach/mach_types.h>
-#include <compat/mach/mach_message.h>
-#include <compat/mach/mach_clock.h>
-#include <compat/mach/mach_syscallargs.h>
-#endif /* _KERNEL_OPT */
-
-const char *const mach_syscallnames[] = {
-	/*   0 */	"#0 (unimplemented)",
-	/*   1 */	"#1 (unimplemented)",
-	/*   2 */	"#2 (unimplemented)",
-	/*   3 */	"#3 (unimplemented)",
-	/*   4 */	"#4 (unimplemented)",
-	/*   5 */	"#5 (unimplemented)",
-	/*   6 */	"#6 (unimplemented)",
-	/*   7 */	"#7 (unimplemented)",
-	/*   8 */	"#8 (unimplemented)",
-	/*   9 */	"#9 (unimplemented)",
-	/*  10 */	"#10 (unimplemented)",
-	/*  11 */	"#11 (unimplemented)",
-	/*  12 */	"#12 (unimplemented)",
-	/*  13 */	"#13 (unimplemented)",
-	/*  14 */	"#14 (unimplemented)",
-	/*  15 */	"#15 (unimplemented)",
-	/*  16 */	"#16 (unimplemented)",
-	/*  17 */	"#17 (unimplemented)",
-	/*  18 */	"#18 (unimplemented)",
-	/*  19 */	"#19 (unimplemented)",
-	/*  20 */	"#20 (unimplemented)",
-	/*  21 */	"#21 (unimplemented)",
-	/*  22 */	"#22 (unimplemented)",
-	/*  23 */	"#23 (unimplemented)",
-	/*  24 */	"#24 (unimplemented)",
-	/*  25 */	"#25 (unimplemented)",
-	/*  26 */	"reply_port",
-	/*  27 */	"thread_self_trap",
-	/*  28 */	"task_self_trap",
-	/*  29 */	"host_self_trap",
-	/*  30 */	"#30 (unimplemented)",
-	/*  31 */	"msg_trap",
-	/*  32 */	"msg_overwrite_trap",
-	/*  33 */	"semaphore_signal_trap",
-	/*  34 */	"semaphore_signal_all_trap",
-	/*  35 */	"semaphore_signal_thread_trap",
-	/*  36 */	"semaphore_wait_trap",
-	/*  37 */	"semaphore_wait_signal_trap",
-	/*  38 */	"semaphore_timedwait_trap",
-	/*  39 */	"semaphore_timedwait_signal_trap",
-	/*  40 */	"#40 (unimplemented)",
-	/*  41 */	"init_process",
-	/*  42 */	"#42 (unimplemented)",
-	/*  43 */	"map_fd",
-	/*  44 */	"#44 (unimplemented)",
-	/*  45 */	"task_for_pid",
-	/*  46 */	"pid_for_task",
-	/*  47 */	"#47 (unimplemented)",
-	/*  48 */	"macx_swapon",
-	/*  49 */	"macx_swapoff",
-	/*  50 */	"#50 (unimplemented)",
-	/*  51 */	"macx_triggers",
-	/*  52 */	"#52 (unimplemented)",
-	/*  53 */	"#53 (unimplemented)",
-	/*  54 */	"#54 (unimplemented)",
-	/*  55 */	"#55 (unimplemented)",
-	/*  56 */	"#56 (unimplemented)",
-	/*  57 */	"#57 (unimplemented)",
-	/*  58 */	"#58 (unimplemented)",
-	/*  59 */	"swtch_pri",
-	/*  60 */	"swtch",
-	/*  61 */	"syscall_thread_switch",
-	/*  62 */	"clock_sleep_trap",
-	/*  63 */	"#63 (unimplemented)",
-	/*  64 */	"#64 (unimplemented)",
-	/*  65 */	"#65 (unimplemented)",
-	/*  66 */	"#66 (unimplemented)",
-	/*  67 */	"#67 (unimplemented)",
-	/*  68 */	"#68 (unimplemented)",
-	/*  69 */	"#69 (unimplemented)",
-	/*  70 */	"#70 (unimplemented)",
-	/*  71 */	"#71 (unimplemented)",
-	/*  72 */	"#72 (unimplemented)",
-	/*  73 */	"#73 (unimplemented)",
-	/*  74 */	"#74 (unimplemented)",
-	/*  75 */	"#75 (unimplemented)",
-	/*  76 */	"#76 (unimplemented)",
-	/*  77 */	"#77 (unimplemented)",
-	/*  78 */	"#78 (unimplemented)",
-	/*  79 */	"#79 (unimplemented)",
-	/*  80 */	"#80 (unimplemented)",
-	/*  81 */	"#81 (unimplemented)",
-	/*  82 */	"#82 (unimplemented)",
-	/*  83 */	"#83 (unimplemented)",
-	/*  84 */	"#84 (unimplemented)",
-	/*  85 */	"#85 (unimplemented)",
-	/*  86 */	"#86 (unimplemented)",
-	/*  87 */	"#87 (unimplemented)",
-	/*  88 */	"#88 (unimplemented)",
-	/*  89 */	"timebase_info",
-	/*  90 */	"wait_until",
-	/*  91 */	"timer_create",
-	/*  92 */	"timer_destroy",
-	/*  93 */	"timer_arm",
-	/*  94 */	"timer_cancel",
-	/*  95 */	"get_time_base_info",
-	/*  96 */	"#96 (unimplemented)",
-	/*  97 */	"#97 (unimplemented)",
-	/*  98 */	"#98 (unimplemented)",
-	/*  99 */	"#99 (unimplemented)",
-	/* 100 */	"#100 (unimplemented)",
-	/* 101 */	"#101 (unimplemented)",
-	/* 102 */	"#102 (unimplemented)",
-	/* 103 */	"#103 (unimplemented)",
-	/* 104 */	"#104 (unimplemented)",
-	/* 105 */	"#105 (unimplemented)",
-	/* 106 */	"#106 (unimplemented)",
-	/* 107 */	"#107 (unimplemented)",
-	/* 108 */	"#108 (unimplemented)",
-	/* 109 */	"#109 (unimplemented)",
-	/* 110 */	"#110 (unimplemented)",
-	/* 111 */	"#111 (unimplemented)",
-	/* 112 */	"#112 (unimplemented)",
-	/* 113 */	"#113 (unimplemented)",
-	/* 114 */	"#114 (unimplemented)",
-	/* 115 */	"#115 (unimplemented)",
-	/* 116 */	"#116 (unimplemented)",
-	/* 117 */	"#117 (unimplemented)",
-	/* 118 */	"#118 (unimplemented)",
-	/* 119 */	"#119 (unimplemented)",
-	/* 120 */	"#120 (unimplemented)",
-	/* 121 */	"#121 (unimplemented)",
-	/* 122 */	"#122 (unimplemented)",
-	/* 123 */	"#123 (unimplemented)",
-	/* 124 */	"#124 (unimplemented)",
-	/* 125 */	"#125 (unimplemented)",
-	/* 126 */	"#126 (unimplemented)",
-	/* 127 */	"#127 (unimplemented)",
+	"#0",			/* 0 = nosys */
+	"#1",			/* 1 = nosys */
+	"#2",			/* 2 = nosys */
+	"#3",			/* 3 = nosys */
+	"#4",			/* 4 = nosys */
+	"#5",			/* 5 = nosys */
+	"#6",			/* 6 = nosys */
+	"#7",			/* 7 = nosys */
+	"#8",			/* 8 = nosys */
+	"#9",			/* 9 = nosys */
+	"#10",			/* 10 = nosys */
+	"#11",			/* 11 = nosys */
+	"#12",			/* 12 = nosys */
+	"#13",			/* 13 = nosys */
+	"#14",			/* 14 = nosys */
+	"#15",			/* 15 = nosys */
+	"#16",			/* 16 = nosys */
+	"#17",			/* 17 = nosys */
+	"#18",			/* 18 = nosys */
+	"#19",			/* 19 = nosys */
+	"#20",			/* 20 = nosys */
+	"#21",			/* 21 = nosys */
+	"#22",			/* 22 = nosys */
+	"#23",			/* 23 = nosys */
+	"#24",			/* 24 = nosys */
+	"#25",			/* 25 = nosys */
+	"mach_reply_port",			/* 26 = mach_reply_port */
+	"mach_thread_self_trap",			/* 27 = mach_thread_self_trap */
+	"mach_task_self_trap",			/* 28 = mach_task_self_trap */
+	"mach_host_self_trap",			/* 29 = mach_host_self_trap */
+	"#30",			/* 30 = nosys */
+	"mach_msg_trap",			/* 31 = mach_msg_trap */
+	"mach_msg_overwrite_trap",			/* 32 = mach_msg_overwrite_trap */
+	"mach_semaphore_signal_trap",			/* 33 = mach_semaphore_signal_trap */
+	"mach_semaphore_signal_all_trap",			/* 34 = mach_semaphore_signal_all_trap */
+	"mach_semaphore_signal_thread_trap",			/* 35 = mach_semaphore_signal_thread_trap */
+	"mach_semaphore_wait_trap",			/* 36 = mach_semaphore_wait_trap */
+	"mach_semaphore_wait_signal_trap",			/* 37 = mach_semaphore_wait_signal_trap */
+	"mach_semaphore_timedwait_trap",			/* 38 = mach_semaphore_timedwait_trap */
+	"mach_semaphore_timedwait_signal_trap",			/* 39 = mach_semaphore_timedwait_signal_trap */
+	"#40",			/* 40 = nosys */
+	"mach_init_process",			/* 41 = mach_init_process */
+	"#42",			/* 42 = nosys */
+	"mach_map_fd",			/* 43 = mach_map_fd */
+	"#44",			/* 44 = nosys */
+	"mach_task_for_pid",			/* 45 = mach_task_for_pid */
+	"mach_pid_for_task",			/* 46 = mach_pid_for_task */
+	"#47",			/* 47 = nosys */
+	"mach_macx_swapon",			/* 48 = mach_macx_swapon */
+	"mach_macx_swapoff",			/* 49 = mach_macx_swapoff */
+	"#50",			/* 50 = nosys */
+	"mach_macx_triggers",			/* 51 = mach_macx_triggers */
+	"#52",			/* 52 = nosys */
+	"#53",			/* 53 = nosys */
+	"#54",			/* 54 = nosys */
+	"#55",			/* 55 = nosys */
+	"#56",			/* 56 = nosys */
+	"#57",			/* 57 = nosys */
+	"#58",			/* 58 = nosys */
+	"mach_swtch_pri",			/* 59 = mach_swtch_pri */
+	"mach_swtch",			/* 60 = mach_swtch */
+	"mach_syscall_thread_switch",			/* 61 = mach_syscall_thread_switch */
+	"mach_clock_sleep_trap",			/* 62 = mach_clock_sleep_trap */
+	"#63",			/* 63 = nosys */
+	"#64",			/* 64 = nosys */
+	"#65",			/* 65 = nosys */
+	"#66",			/* 66 = nosys */
+	"#67",			/* 67 = nosys */
+	"#68",			/* 68 = nosys */
+	"#69",			/* 69 = nosys */
+	"#70",			/* 70 = nosys */
+	"#71",			/* 71 = nosys */
+	"#72",			/* 72 = nosys */
+	"#73",			/* 73 = nosys */
+	"#74",			/* 74 = nosys */
+	"#75",			/* 75 = nosys */
+	"#76",			/* 76 = nosys */
+	"#77",			/* 77 = nosys */
+	"#78",			/* 78 = nosys */
+	"#79",			/* 79 = nosys */
+	"#80",			/* 80 = nosys */
+	"#81",			/* 81 = nosys */
+	"#82",			/* 82 = nosys */
+	"#83",			/* 83 = nosys */
+	"#84",			/* 84 = nosys */
+	"#85",			/* 85 = nosys */
+	"#86",			/* 86 = nosys */
+	"#87",			/* 87 = nosys */
+	"#88",			/* 88 = nosys */
+	"mach_timebase_info",			/* 89 = mach_timebase_info */
+	"mach_wait_until",			/* 90 = mach_wait_until */
+	"mach_timer_create",			/* 91 = mach_timer_create */
+	"mach_timer_destroy",			/* 92 = mach_timer_destroy */
+	"mach_timer_arm",			/* 93 = mach_timer_arm */
+	"mach_timer_cancel",			/* 94 = mach_timer_cancel */
+	"mach_get_time_base_info",			/* 95 = mach_get_time_base_info */
+	"#96",			/* 96 = nosys */
+	"#97",			/* 97 = nosys */
+	"#98",			/* 98 = nosys */
+	"#99",			/* 99 = nosys */
+	"#100",			/* 100 = nosys */
+	"#101",			/* 101 = nosys */
+	"#102",			/* 102 = nosys */
+	"#103",			/* 103 = nosys */
+	"#104",			/* 104 = nosys */
+	"#105",			/* 105 = nosys */
+	"#106",			/* 106 = nosys */
+	"#107",			/* 107 = nosys */
+	"#108",			/* 108 = nosys */
+	"#109",			/* 109 = nosys */
+	"#110",			/* 110 = nosys */
+	"#111",			/* 111 = nosys */
+	"#112",			/* 112 = nosys */
+	"#113",			/* 113 = nosys */
+	"#114",			/* 114 = nosys */
+	"#115",			/* 115 = nosys */
+	"#116",			/* 116 = nosys */
+	"#117",			/* 117 = nosys */
+	"#118",			/* 118 = nosys */
+	"#119",			/* 119 = nosys */
+	"#120",			/* 120 = nosys */
+	"#121",			/* 121 = nosys */
+	"#122",			/* 122 = nosys */
+	"#123",			/* 123 = nosys */
+	"#124",			/* 124 = nosys */
+	"#125",			/* 125 = nosys */
+	"#126",			/* 126 = nosys */
+	"#127",			/* 127 = nosys */
 };
diff --git a/sys/compat/mach/mach_sysctl.c b/sys/compat/mach/mach_sysctl.c
index 07421ee..e5810bd 100644
--- a/sys/compat/mach/mach_sysctl.c
+++ b/sys/compat/mach/mach_sysctl.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_sysctl.c,v 1.4 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,6 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_sysctl.c,v 1.4 2008/04/28 20:23:44 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
diff --git a/sys/compat/mach/mach_sysctl.h b/sys/compat/mach/mach_sysctl.h
index 6f6a422..586bd68 100644
--- a/sys/compat/mach/mach_sysctl.h
+++ b/sys/compat/mach/mach_sysctl.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_sysctl.h,v 1.3 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
diff --git a/sys/compat/mach/mach_sysent.c b/sys/compat/mach/mach_sysent.c
index fc925f6..4ed4baf 100644
--- a/sys/compat/mach/mach_sysent.c
+++ b/sys/compat/mach/mach_sysent.c
@@ -1,289 +1,156 @@
-/* $NetBSD: mach_sysent.c,v 1.23 2009/12/14 00:58:37 matt Exp $ */
-
 /*
  * System call switch table.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.10 2009/01/13 22:27:43 pooka Exp
+ * $FreeBSD$
+ * created from	FreeBSD
  */
 
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_sysent.c,v 1.23 2009/12/14 00:58:37 matt Exp $");
-
-#if defined(_KERNEL_OPT)
 #include "opt_ntp.h"
-#include "opt_sysv.h"
-#endif
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/signal.h>
 #include <sys/mount.h>
 #include <sys/poll.h>
-#include <sys/syscallargs.h>
+#include <sys/sysent.h>
+#include <sys/sysproto.h>
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
 #include <compat/mach/mach_clock.h>
-#include <compat/mach/mach_syscallargs.h>
+#include <compat/mach/mach_proto.h>
 
-#define	s(type)	sizeof(type)
-#define	n(type)	(sizeof(type)/sizeof (register_t))
-#define	ns(type)	n(type), s(type)
+#define AS(name) (sizeof(struct name) / sizeof(register_t))
 
+/* The casts are bogus but will do for now. */
 struct sysent mach_sysent[] = {
-	{ 0, 0, 0,
-	    sys_nosys },			/* 0 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 1 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 2 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 3 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 4 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 5 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 6 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 7 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 8 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 9 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 10 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 11 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 12 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 13 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 14 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 15 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 16 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 17 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 18 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 19 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 20 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 21 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 22 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 23 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 24 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 25 = unimplemented */
-	{ 0, 0, 0,
-	    (sy_call_t *)mach_sys_reply_port },	/* 26 = reply_port */
-	{ 0, 0, 0,
-	    (sy_call_t *)mach_sys_thread_self_trap },/* 27 = thread_self_trap */
-	{ 0, 0, 0,
-	    (sy_call_t *)mach_sys_task_self_trap },/* 28 = task_self_trap */
-	{ 0, 0, 0,
-	    (sy_call_t *)mach_sys_host_self_trap },/* 29 = host_self_trap */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 30 = unimplemented */
-	{ ns(struct mach_sys_msg_trap_args), 0,
-	    (sy_call_t *)mach_sys_msg_trap },	/* 31 = msg_trap */
-	{ ns(struct mach_sys_msg_overwrite_trap_args), 0,
-	    (sy_call_t *)mach_sys_msg_overwrite_trap },/* 32 = msg_overwrite_trap */
-	{ ns(struct mach_sys_semaphore_signal_trap_args), 0,
-	    (sy_call_t *)mach_sys_semaphore_signal_trap },/* 33 = semaphore_signal_trap */
-	{ ns(struct mach_sys_semaphore_signal_all_trap_args), 0,
-	    (sy_call_t *)mach_sys_semaphore_signal_all_trap },/* 34 = semaphore_signal_all_trap */
-	{ ns(struct mach_sys_semaphore_signal_thread_trap_args), 0,
-	    (sy_call_t *)mach_sys_semaphore_signal_thread_trap },/* 35 = semaphore_signal_thread_trap */
-	{ ns(struct mach_sys_semaphore_wait_trap_args), 0,
-	    (sy_call_t *)mach_sys_semaphore_wait_trap },/* 36 = semaphore_wait_trap */
-	{ ns(struct mach_sys_semaphore_wait_signal_trap_args), 0,
-	    (sy_call_t *)mach_sys_semaphore_wait_signal_trap },/* 37 = semaphore_wait_signal_trap */
-	{ ns(struct mach_sys_semaphore_timedwait_trap_args), 0,
-	    (sy_call_t *)mach_sys_semaphore_timedwait_trap },/* 38 = semaphore_timedwait_trap */
-	{ ns(struct mach_sys_semaphore_timedwait_signal_trap_args), 0,
-	    (sy_call_t *)mach_sys_semaphore_timedwait_signal_trap },/* 39 = semaphore_timedwait_signal_trap */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 40 = unimplemented */
-	{ 0, 0, 0,
-	    (sy_call_t *)mach_sys_init_process },/* 41 = init_process */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 42 = unimplemented */
-	{ ns(struct mach_sys_map_fd_args), 0,
-	    (sy_call_t *)mach_sys_map_fd },	/* 43 = map_fd */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 44 = unimplemented */
-	{ ns(struct mach_sys_task_for_pid_args), 0,
-	    (sy_call_t *)mach_sys_task_for_pid },/* 45 = task_for_pid */
-	{ ns(struct mach_sys_pid_for_task_args), 0,
-	    (sy_call_t *)mach_sys_pid_for_task },/* 46 = pid_for_task */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 47 = unimplemented */
-	{ ns(struct mach_sys_macx_swapon_args), 0,
-	    (sy_call_t *)mach_sys_macx_swapon },/* 48 = macx_swapon */
-	{ ns(struct mach_sys_macx_swapoff_args), 0,
-	    (sy_call_t *)mach_sys_macx_swapoff },/* 49 = macx_swapoff */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 50 = unimplemented */
-	{ ns(struct mach_sys_macx_triggers_args), 0,
-	    (sy_call_t *)mach_sys_macx_triggers },/* 51 = macx_triggers */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 52 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 53 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 54 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 55 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 56 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 57 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 58 = unimplemented */
-	{ ns(struct mach_sys_swtch_pri_args), 0,
-	    (sy_call_t *)mach_sys_swtch_pri },	/* 59 = swtch_pri */
-	{ 0, 0, 0,
-	    (sy_call_t *)mach_sys_swtch },	/* 60 = swtch */
-	{ ns(struct mach_sys_syscall_thread_switch_args), 0,
-	    (sy_call_t *)mach_sys_syscall_thread_switch },/* 61 = syscall_thread_switch */
-	{ ns(struct mach_sys_clock_sleep_trap_args), 0,
-	    (sy_call_t *)mach_sys_clock_sleep_trap },/* 62 = clock_sleep_trap */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 63 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 64 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 65 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 66 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 67 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 68 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 69 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 70 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 71 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 72 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 73 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 74 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 75 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 76 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 77 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 78 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 79 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 80 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 81 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 82 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 83 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 84 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 85 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 86 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 87 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 88 = unimplemented */
-	{ ns(struct mach_sys_timebase_info_args), 0,
-	    (sy_call_t *)mach_sys_timebase_info },/* 89 = timebase_info */
-	{ ns(struct mach_sys_wait_until_args), 0,
-	    (sy_call_t *)mach_sys_wait_until },	/* 90 = wait_until */
-	{ 0, 0, 0,
-	    (sy_call_t *)mach_sys_timer_create },/* 91 = timer_create */
-	{ ns(struct mach_sys_timer_destroy_args), 0,
-	    (sy_call_t *)mach_sys_timer_destroy },/* 92 = timer_destroy */
-	{ ns(struct mach_sys_timer_arm_args), 0,
-	    (sy_call_t *)mach_sys_timer_arm },	/* 93 = timer_arm */
-	{ ns(struct mach_sys_timer_cancel_args), 0,
-	    (sy_call_t *)mach_sys_timer_cancel },/* 94 = timer_cancel */
-	{ 0, 0, 0,
-	    (sy_call_t *)mach_sys_get_time_base_info },/* 95 = get_time_base_info */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 96 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 97 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 98 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 99 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 100 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 101 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 102 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 103 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 104 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 105 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 106 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 107 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 108 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 109 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 110 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 111 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 112 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 113 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 114 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 115 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 116 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 117 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 118 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 119 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 120 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 121 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 122 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 123 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 124 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 125 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 126 = unimplemented */
-	{ 0, 0, 0,
-	    sys_nosys },			/* 127 = unimplemented */
+#if defined(_KERNEL_OPT)
+#endif
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 0 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 1 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 2 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 3 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 4 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 5 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 6 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 7 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 8 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 9 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 10 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 11 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 12 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 13 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 14 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 15 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 16 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 17 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 18 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 19 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 20 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 21 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 22 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 23 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 24 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 25 = nosys */
+	{ 0, (sy_call_t *)sys_mach_reply_port, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 26 = mach_reply_port */
+	{ 0, (sy_call_t *)sys_mach_thread_self_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 27 = mach_thread_self_trap */
+	{ 0, (sy_call_t *)sys_mach_task_self_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 28 = mach_task_self_trap */
+	{ 0, (sy_call_t *)sys_mach_host_self_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 29 = mach_host_self_trap */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 30 = nosys */
+	{ AS(mach_msg_trap_args), (sy_call_t *)sys_mach_msg_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 31 = mach_msg_trap */
+	{ AS(mach_msg_overwrite_trap_args), (sy_call_t *)sys_mach_msg_overwrite_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 32 = mach_msg_overwrite_trap */
+	{ AS(mach_semaphore_signal_trap_args), (sy_call_t *)sys_mach_semaphore_signal_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 33 = mach_semaphore_signal_trap */
+	{ AS(mach_semaphore_signal_all_trap_args), (sy_call_t *)sys_mach_semaphore_signal_all_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 34 = mach_semaphore_signal_all_trap */
+	{ AS(mach_semaphore_signal_thread_trap_args), (sy_call_t *)sys_mach_semaphore_signal_thread_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 35 = mach_semaphore_signal_thread_trap */
+	{ AS(mach_semaphore_wait_trap_args), (sy_call_t *)sys_mach_semaphore_wait_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 36 = mach_semaphore_wait_trap */
+	{ AS(mach_semaphore_wait_signal_trap_args), (sy_call_t *)sys_mach_semaphore_wait_signal_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 37 = mach_semaphore_wait_signal_trap */
+	{ AS(mach_semaphore_timedwait_trap_args), (sy_call_t *)sys_mach_semaphore_timedwait_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 38 = mach_semaphore_timedwait_trap */
+	{ AS(mach_semaphore_timedwait_signal_trap_args), (sy_call_t *)sys_mach_semaphore_timedwait_signal_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 39 = mach_semaphore_timedwait_signal_trap */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 40 = nosys */
+	{ 0, (sy_call_t *)sys_mach_init_process, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 41 = mach_init_process */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 42 = nosys */
+	{ AS(mach_map_fd_args), (sy_call_t *)sys_mach_map_fd, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 43 = mach_map_fd */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 44 = nosys */
+	{ AS(mach_task_for_pid_args), (sy_call_t *)sys_mach_task_for_pid, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 45 = mach_task_for_pid */
+	{ AS(mach_pid_for_task_args), (sy_call_t *)sys_mach_pid_for_task, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 46 = mach_pid_for_task */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 47 = nosys */
+	{ AS(mach_macx_swapon_args), (sy_call_t *)sys_mach_macx_swapon, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 48 = mach_macx_swapon */
+	{ AS(mach_macx_swapoff_args), (sy_call_t *)sys_mach_macx_swapoff, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 49 = mach_macx_swapoff */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 50 = nosys */
+	{ AS(mach_macx_triggers_args), (sy_call_t *)sys_mach_macx_triggers, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 51 = mach_macx_triggers */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 52 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 53 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 54 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 55 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 56 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 57 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 58 = nosys */
+	{ AS(mach_swtch_pri_args), (sy_call_t *)sys_mach_swtch_pri, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 59 = mach_swtch_pri */
+	{ 0, (sy_call_t *)sys_mach_swtch, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 60 = mach_swtch */
+	{ AS(mach_syscall_thread_switch_args), (sy_call_t *)sys_mach_syscall_thread_switch, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 61 = mach_syscall_thread_switch */
+	{ AS(mach_clock_sleep_trap_args), (sy_call_t *)sys_mach_clock_sleep_trap, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 62 = mach_clock_sleep_trap */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 63 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 64 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 65 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 66 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 67 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 68 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 69 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 70 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 71 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 72 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 73 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 74 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 75 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 76 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 77 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 78 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 79 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 80 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 81 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 82 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 83 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 84 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 85 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 86 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 87 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 88 = nosys */
+	{ AS(mach_timebase_info_args), (sy_call_t *)sys_mach_timebase_info, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 89 = mach_timebase_info */
+	{ AS(mach_wait_until_args), (sy_call_t *)sys_mach_wait_until, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 90 = mach_wait_until */
+	{ 0, (sy_call_t *)sys_mach_timer_create, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 91 = mach_timer_create */
+	{ AS(mach_timer_destroy_args), (sy_call_t *)sys_mach_timer_destroy, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 92 = mach_timer_destroy */
+	{ AS(mach_timer_arm_args), (sy_call_t *)sys_mach_timer_arm, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 93 = mach_timer_arm */
+	{ AS(mach_timer_cancel_args), (sy_call_t *)sys_mach_timer_cancel, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 94 = mach_timer_cancel */
+	{ 0, (sy_call_t *)sys_mach_get_time_base_info, AUE_NULL, NULL, 0, 0, 0, SY_THR_STATIC },	/* 95 = mach_get_time_base_info */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 96 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 97 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 98 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 99 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 100 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 101 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 102 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 103 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 104 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 105 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 106 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 107 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 108 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 109 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 110 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 111 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 112 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 113 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 114 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 115 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 116 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 117 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 118 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 119 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 120 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 121 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 122 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 123 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 124 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 125 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 126 = nosys */
+	{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },			/* 127 = nosys */
 };
diff --git a/sys/compat/mach/mach_task.c b/sys/compat/mach/mach_task.c
index d37c571..b67762f 100644
--- a/sys/compat/mach/mach_task.c
+++ b/sys/compat/mach/mach_task.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_task.c,v 1.72 2010/07/01 02:38:29 rmind Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002-2003, 2008 The NetBSD Foundation, Inc.
@@ -29,10 +29,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "opt_compat_darwin.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.72 2010/07/01 02:38:29 rmind Exp $");
+__FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -43,7 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.72 2010/07/01 02:38:29 rmind Exp $")
 #include <sys/resourcevar.h>
 #include <sys/malloc.h>
 #include <sys/mount.h>
-#include <sys/syscallargs.h>
+#include <sys/sysproto.h>
 #include <sys/kauth.h>
 
 #include <uvm/uvm_extern.h>
@@ -57,7 +56,7 @@ __KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.72 2010/07/01 02:38:29 rmind Exp $")
 #include <compat/mach/mach_port.h>
 #include <compat/mach/mach_task.h>
 #include <compat/mach/mach_services.h>
-#include <compat/mach/mach_syscallargs.h>
+#include <compat/mach/mach_proto.h>
 
 #ifdef COMPAT_DARWIN
 #include <compat/darwin/darwin_exec.h>
@@ -74,25 +73,25 @@ mach_task_get_special_port(struct mach_trap_args *args)
 	mach_task_get_special_port_request_t *req = args->smsg;
 	mach_task_get_special_port_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
-	struct lwp *tl = args->tl;
+	struct thread *td = args->td;
+	struct thread *ttd = args->ttd;
 	struct mach_emuldata *med;
 	struct mach_right *mr;
 
-	med = (struct mach_emuldata *)tl->l_proc->p_emuldata;
+	med = (struct mach_emuldata *)ttd->td_proc->p_emuldata;
 
 	switch (req->req_which_port) {
 	case MACH_TASK_KERNEL_PORT:
-		mr = mach_right_get(med->med_kernel, l, MACH_PORT_TYPE_SEND, 0);
+		mr = mach_right_get(med->med_kernel, td, MACH_PORT_TYPE_SEND, 0);
 		break;
 
 	case MACH_TASK_HOST_PORT:
-		mr = mach_right_get(med->med_host, l, MACH_PORT_TYPE_SEND, 0);
+		mr = mach_right_get(med->med_host, td, MACH_PORT_TYPE_SEND, 0);
 		break;
 
 	case MACH_TASK_BOOTSTRAP_PORT:
 		mr = mach_right_get(med->med_bootstrap,
-		    l, MACH_PORT_TYPE_SEND, 0);
+		    td, MACH_PORT_TYPE_SEND, 0);
 		break;
 
 	case MACH_TASK_WIRED_LEDGER_PORT:
@@ -118,8 +117,8 @@ mach_ports_lookup(struct mach_trap_args *args)
 	mach_ports_lookup_request_t *req = args->smsg;
 	mach_ports_lookup_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
-	struct lwp *tl = args->tl;
+	struct thread *td = args->td;
+	struct thread *ttd = args->ttd;
 	struct mach_emuldata *med;
 	struct mach_right *mr;
 	mach_port_name_t mnp[7];
@@ -133,17 +132,17 @@ mach_ports_lookup(struct mach_trap_args *args)
 	 * filled. We have to see more of this in order to fully understand
 	 * how this trap works.
 	 */
-	med = (struct mach_emuldata *)tl->l_proc->p_emuldata;
+	med = (struct mach_emuldata *)ttd->td_proc->p_emuldata;
 	mnp[0] = (mach_port_name_t)MACH_PORT_DEAD;
 	mnp[3] = (mach_port_name_t)MACH_PORT_DEAD;
 	mnp[5] = (mach_port_name_t)MACH_PORT_DEAD;
 	mnp[6] = (mach_port_name_t)MACH_PORT_DEAD;
 
-	mr = mach_right_get(med->med_kernel, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(med->med_kernel, td, MACH_PORT_TYPE_SEND, 0);
 	mnp[MACH_TASK_KERNEL_PORT] = mr->mr_name;
-	mr = mach_right_get(med->med_host, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(med->med_host, td, MACH_PORT_TYPE_SEND, 0);
 	mnp[MACH_TASK_HOST_PORT] = mr->mr_name;
-	mr = mach_right_get(med->med_bootstrap, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(med->med_bootstrap, td, MACH_PORT_TYPE_SEND, 0);
 	mnp[MACH_TASK_BOOTSTRAP_PORT] = mr->mr_name;
 
 	/*
@@ -173,8 +172,8 @@ mach_task_set_special_port(struct mach_trap_args *args)
 	mach_task_set_special_port_request_t *req = args->smsg;
 	mach_task_set_special_port_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
-	struct lwp *tl = args->tl;
+	struct thread *td = args->td;
+	struct thread *ttd = args->ttd;
 	mach_port_t mn;
 	struct mach_right *mr;
 	struct mach_port *mp;
@@ -187,13 +186,13 @@ mach_task_set_special_port(struct mach_trap_args *args)
 		return mach_msg_error(args, 0);
 
 	/* Does the inserted port exists? */
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == 0)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_ALL_RIGHTS)) == 0)
 		return mach_msg_error(args, EPERM);
 
 	if (mr->mr_type == MACH_PORT_TYPE_DEAD_NAME)
 		return mach_msg_error(args, EINVAL);
 
-	med = (struct mach_emuldata *)tl->l_proc->p_emuldata;
+	med = (struct mach_emuldata *)ttd->td_proc->p_emuldata;
 
 	switch (req->req_which_port) {
 	case MACH_TASK_KERNEL_PORT:
@@ -225,7 +224,7 @@ mach_task_set_special_port(struct mach_trap_args *args)
 		{
 			struct darwin_emuldata *ded;
 
-			ded = tl->l_proc->p_emuldata;
+			ded = ttd->td_proc->p_emuldata;
 			if (ded->ded_fakepid == 1) {
 				mach_bootstrap_port = med->med_bootstrap;
 #ifdef DEBUG_DARWIN
@@ -261,9 +260,9 @@ mach_task_threads(struct mach_trap_args *args)
 	mach_task_threads_request_t *req = args->smsg;
 	mach_task_threads_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
-	struct lwp *tl = args->tl;
-	struct proc *tp = tl->l_proc;
+	struct thread *td = args->td;
+	struct thread *ttd = args->ttd;
+	struct proc *tp = ttd->td_proc;
 	struct lwp *cl;
 	struct mach_emuldata *med;
 	struct mach_lwp_emuldata *mle;
@@ -281,7 +280,7 @@ mach_task_threads(struct mach_trap_args *args)
 
 	LIST_FOREACH(cl, &tp->p_lwps, l_sibling) {
 		mle = cl->l_emuldata;
-		mr = mach_right_get(mle->mle_kernel, l, MACH_PORT_TYPE_SEND, 0);
+		mr = mach_right_get(mle->mle_kernel, td, MACH_PORT_TYPE_SEND, 0);
 		mnp[i++] = mr->mr_name;
 	}
 
@@ -306,15 +305,15 @@ mach_task_get_exception_ports(struct mach_trap_args *args)
 {
 	mach_task_get_exception_ports_request_t *req = args->smsg;
 	mach_task_get_exception_ports_reply_t *rep = args->rmsg;
-	struct lwp *l = args->l;
-	struct lwp *tl = args->tl;
+	struct thread *td = args->td;
+	struct thread *ttd = args->ttd;
 	size_t *msglen = args->rsize;
 	struct mach_emuldata *med;
 	struct mach_right *mr;
 	struct mach_exc_info *mei;
 	int i, j, count;
 
-	med = tl->l_proc->p_emuldata;
+	med = ttd->td_proc->p_emuldata;
 
 	/* It always returns an array of 32 ports even if only 9 can be used */
 	count = sizeof(rep->rep_old_handler) / sizeof(rep->rep_old_handler[0]);
@@ -336,7 +335,7 @@ mach_task_get_exception_ports(struct mach_trap_args *args)
 		}
 		mei = med->med_exc[i]->mp_data;
 
-		mr = mach_right_get(med->med_exc[i], l, MACH_PORT_TYPE_SEND, 0);
+		mr = mach_right_get(med->med_exc[i], td, MACH_PORT_TYPE_SEND, 0);
 
 		mach_add_port_desc(rep, mr->mr_name);
 
@@ -369,8 +368,8 @@ mach_task_set_exception_ports(struct mach_trap_args *args)
 {
 	mach_task_set_exception_ports_request_t *req = args->smsg;
 	mach_task_set_exception_ports_reply_t *rep = args->rmsg;
-	struct lwp *l = args->l;
-	struct lwp *tl = args->tl;
+	struct thread *td = args->td;
+	struct thread *ttd = args->ttd;
 	size_t *msglen = args->rsize;
 	struct mach_emuldata *med;
 	mach_port_name_t mn;
@@ -379,7 +378,7 @@ mach_task_set_exception_ports(struct mach_trap_args *args)
 	struct mach_exc_info *mei;
 
 	mn = req->req_new_port.name;
-	if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_SEND)) == 0)
+	if ((mr = mach_right_check(mn, td, MACH_PORT_TYPE_SEND)) == 0)
 		return mach_msg_error(args, EPERM);
 
 	mp = mr->mr_port;
@@ -388,7 +387,7 @@ mach_task_set_exception_ports(struct mach_trap_args *args)
 	    (mp->mp_datatype != MACH_MP_NONE))
 		printf("mach_task_set_exception_ports: data exists\n");
 #endif
-	mei = malloc(sizeof(*mei), M_EMULDATA, M_WAITOK);
+	mei = malloc(sizeof(*mei), M_MACH, M_WAITOK);
 	mei->mei_flavor = req->req_flavor;
 	mei->mei_behavior = req->req_behavior;
 
@@ -396,7 +395,7 @@ mach_task_set_exception_ports(struct mach_trap_args *args)
 	mp->mp_flags |= MACH_MP_DATA_ALLOCATED;
 	mp->mp_datatype = MACH_MP_EXC_INFO;
 
-	med = tl->l_proc->p_emuldata;
+	med = ttd->td_proc->p_emuldata;
 	if (req->req_mask & MACH_EXC_MASK_BAD_ACCESS)
 		update_exception_port(med, MACH_EXC_BAD_ACCESS, mp);
 	if (req->req_mask & MACH_EXC_MASK_BAD_INSTRUCTION)
@@ -439,10 +438,10 @@ mach_task_info(struct mach_trap_args *args)
 {
 	mach_task_info_request_t *req = args->smsg;
 	mach_task_info_reply_t *rep = args->rmsg;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	size_t *msglen = args->rsize;
 	int count;
-	struct proc *tp = tl->l_proc;
+	struct proc *tp = ttd->td_proc;
 
 	switch(req->req_flavor) {
 	case MACH_TASK_BASIC_INFO: {
@@ -542,10 +541,10 @@ mach_task_suspend(struct mach_trap_args *args)
 	mach_task_suspend_request_t *req = args->smsg;
 	mach_task_suspend_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
-	struct lwp *lp;
+	struct thread *ttd = args->ttd;
+	struct thread *tdp;
 	struct mach_emuldata *med;
-	struct proc *tp = tl->l_proc;
+	struct proc *tp = ttd->td_proc;
 
 	med = tp->p_emuldata;
 	med->med_suspend++; /* XXX Mach also has a per thread semaphore */
@@ -585,9 +584,9 @@ mach_task_resume(struct mach_trap_args *args)
 	mach_task_resume_request_t *req = args->smsg;
 	mach_task_resume_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	struct mach_emuldata *med;
-	struct proc *tp = tl->l_proc;
+	struct proc *tp = ttd->td_proc;
 
 	med = tp->p_emuldata;
 	med->med_suspend--; /* XXX Mach also has a per thread semaphore */
@@ -622,13 +621,13 @@ mach_task_terminate(struct mach_trap_args *args)
 	mach_task_resume_request_t *req = args->smsg;
 	mach_task_resume_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	struct sys_exit_args cup;
 	register_t retval;
 	int error;
 
 
-	SCARG(&cup, rval) = 0;
+	&cup->rval = 0;
 	error = sys_exit(tl, &cup, &retval);
 
 	*msglen = sizeof(*rep);
@@ -642,7 +641,7 @@ mach_task_terminate(struct mach_trap_args *args)
 }
 
 int
-mach_sys_task_for_pid(struct lwp *l, const struct mach_sys_task_for_pid_args *uap, register_t *retval)
+mach_sys_task_for_pid(struct thread *td, struct mach_sys_task_for_pid_args *uap)
 {
 	/* {
 		syscallarg(mach_port_t) target_tport;
@@ -661,12 +660,12 @@ mach_sys_task_for_pid(struct lwp *l, const struct mach_sys_task_for_pid_args *ua
 	 * yet, so this parameter should be useless.
 	 * However, we still validate it.
 	 */
-	if ((mr = mach_right_check(SCARG(uap, target_tport),
-	    l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
+	if ((mr = mach_right_check(uap->target_tport,
+	    td, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
 		return EPERM;
 
 	mutex_enter(proc_lock);
-	if ((t = proc_find(SCARG(uap, pid))) == NULL) {
+	if ((t = proc_find(uap->pid)) == NULL) {
 		mutex_exit(proc_lock);
 		return ESRCH;
 	}
@@ -694,9 +693,9 @@ mach_sys_task_for_pid(struct lwp *l, const struct mach_sys_task_for_pid_args *ua
 
 	/* XXX: Unlocked, broken. */
 	med = t->p_emuldata;
-	mr = mach_right_get(med->med_kernel, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(med->med_kernel, td, MACH_PORT_TYPE_SEND, 0);
 	if (mr) {
-		error = copyout(&mr->mr_name, SCARG(uap, t),
+		error = copyout(&mr->mr_name, uap->t,
 		    sizeof(mr->mr_name));
 	} else {
 		error = EINVAL;
diff --git a/sys/compat/mach/mach_task.h b/sys/compat/mach/mach_task.h
index e0ea1f8..ed5e8ff 100644
--- a/sys/compat/mach/mach_task.h
+++ b/sys/compat/mach/mach_task.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_task.h,v 1.16 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
diff --git a/sys/compat/mach/mach_thread.c b/sys/compat/mach/mach_thread.c
index a5abd61..36bccba 100644
--- a/sys/compat/mach/mach_thread.c
+++ b/sys/compat/mach/mach_thread.c
@@ -1,5 +1,3 @@
-/*	$NetBSD: mach_thread.c,v 1.50 2010/06/13 04:13:31 yamt Exp $ */
-
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,13 +28,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_thread.c,v 1.50 2010/06/13 04:13:31 yamt Exp $");
+__FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/kernel.h>
 #include <sys/systm.h>
 #include <sys/signal.h>
+#include <sys/lock.h>
 #include <sys/rwlock.h>
 #include <sys/queue.h>
 #include <sys/proc.h>
@@ -54,10 +53,10 @@ __KERNEL_RCSID(0, "$NetBSD: mach_thread.c,v 1.50 2010/06/13 04:13:31 yamt Exp $"
 #include <compat/mach/mach_thread.h>
 #include <compat/mach/mach_errno.h>
 #include <compat/mach/mach_services.h>
-#include <compat/mach/mach_syscallargs.h>
+#include <compat/mach/mach_proto.h>
 
 int
-mach_sys_syscall_thread_switch(struct lwp *l, const struct mach_sys_syscall_thread_switch_args *uap, register_t *retval)
+mach_sys_syscall_thread_switch(struct thread *td, const struct mach_sys_syscall_thread_switch_args *uap)
 {
 	/* {
 		syscallarg(mach_port_name_t) thread_name;
@@ -67,15 +66,15 @@ mach_sys_syscall_thread_switch(struct lwp *l, const struct mach_sys_syscall_thre
 	int timeout;
 	struct mach_emuldata *med;
 
-	med = (struct mach_emuldata *)l->l_proc->p_emuldata;
-	timeout = SCARG(uap, option_time) * hz / 1000;
+	med = (struct mach_emuldata *)td->td_proc->p_emuldata;
+	timeout = uap->option_time * hz / 1000;
 
 	/*
 	 * The day we will be able to find out the struct proc from
 	 * the port number, try to use preempt() to call the right thread.
 	 * [- but preempt() is for _involuntary_ context switches.]
 	 */
-	switch(SCARG(uap, option)) {
+	switch(uap->option) {
 	case MACH_SWITCH_OPTION_NONE:
 		yield();
 		break;
@@ -95,14 +94,14 @@ mach_sys_syscall_thread_switch(struct lwp *l, const struct mach_sys_syscall_thre
 		break;
 
 	default:
-		uprintf("mach_sys_syscall_thread_switch(): unknown option %d\n",		    SCARG(uap, option));
+		uprintf("mach_sys_syscall_thread_switch(): unknown option %d\n",		    uap->option);
 		break;
 	}
 	return 0;
 }
 
 int
-mach_sys_swtch_pri(struct lwp *l, const struct mach_sys_swtch_pri_args *uap, register_t *retval)
+mach_sys_swtch_pri(struct thread *td, struct mach_sys_swtch_pri_args *uap)
 {
 	/* {
 		syscallarg(int) pri;
@@ -115,21 +114,21 @@ mach_sys_swtch_pri(struct lwp *l, const struct mach_sys_swtch_pri_args *uap, reg
 	KERNEL_UNLOCK_ALL(l, &l->l_biglocks);
 	lwp_lock(l);
 	if (l->l_stat == LSONPROC)
-		l->l_proc->p_stats->p_ru.ru_nivcsw++;	/* XXXSMP */
-	*retval = mi_switch(l);
+		td->td_proc->p_stats->p_ru.ru_nivcsw++;	/* XXXSMP */
+	td->td_retval[0] = mi_switch(td);
 	KERNEL_LOCK(l->l_biglocks, l);
 
 	return 0;
 }
 
 int
-mach_sys_swtch(struct lwp *l, const void *v, register_t *retval)
+mach_sys_swtch(struct thread *td, const void *v)
 {
 	struct mach_sys_swtch_pri_args cup;
 
-	SCARG(&cup, pri) = 0;
+	cup.pri = 0;
 
-	return mach_sys_swtch_pri(l, &cup, retval);
+	return mach_sys_swtch_pri(td, &cup, retval);
 }
 
 
@@ -166,12 +165,12 @@ mach_thread_create_running(struct mach_trap_args *args)
 	mach_thread_create_running_request_t *req = args->smsg;
 	mach_thread_create_running_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
-	struct proc *p = l->l_proc;
+	struct thread *td = args->td;
+	struct proc *p = td->td_proc;
 	struct mach_create_thread_child_args mctc;
 	struct mach_right *child_mr;
 	struct mach_lwp_emuldata *mle;
-	vaddr_t uaddr;
+	vm_offset_t uaddr;
 	int flags;
 	int error;
 	int end_offset;
@@ -217,7 +216,7 @@ mach_thread_create_running(struct mach_trap_args *args)
 	 * Get the child's kernel port
 	 */
 	mle = mctc.mctc_lwp->l_emuldata;
-	child_mr = mach_right_get(mle->mle_kernel, l, MACH_PORT_TYPE_SEND, 0);
+	child_mr = mach_right_get(mle->mle_kernel, td, MACH_PORT_TYPE_SEND, 0);
 
 	/*
 	 * The child relies on some values in mctc, so we should not
@@ -243,9 +242,9 @@ mach_thread_info(struct mach_trap_args *args)
 	mach_thread_info_request_t *req = args->smsg;
 	mach_thread_info_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
-	struct lwp *tl = args->tl;
-	struct proc *tp = tl->l_proc;
+	struct thread *td = args->td;
+	struct thread *ttd = args->ttd;
+	struct proc *tp = ttd->td_proc;
 
 	/* Sanity check req->req_count */
 	if (req->req_count > 12)
@@ -335,7 +334,7 @@ mach_thread_get_state(struct mach_trap_args *args)
 	mach_thread_get_state_request_t *req = args->smsg;
 	mach_thread_get_state_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	int error;
 	int size;
 
@@ -361,7 +360,7 @@ mach_thread_set_state(struct mach_trap_args *args)
 	mach_thread_set_state_request_t *req = args->smsg;
 	mach_thread_set_state_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	int error;
 	int end_offset;
 
@@ -390,9 +389,9 @@ mach_thread_suspend(struct mach_trap_args *args)
 	mach_thread_suspend_request_t *req = args->smsg;
 	mach_thread_suspend_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
-	struct lwp *tl = args->tl;
-	struct proc *p = tl->l_proc;
+	struct thread *td = args->td;
+	struct thread *ttd = args->ttd;
+	struct proc *p = ttd->td_proc;
 	int error;
 
 	mutex_enter(p->p_lock);
@@ -414,8 +413,8 @@ mach_thread_resume(struct mach_trap_args *args)
 	mach_thread_resume_request_t *req = args->smsg;
 	mach_thread_resume_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
-	struct proc *p = tl->l_proc;
+	struct thread *ttd = args->ttd;
+	struct proc *p = ttd->td_proc;
 
 	mutex_enter(p->p_lock);
 	lwp_lock(tl);
@@ -436,7 +435,7 @@ mach_thread_abort(struct mach_trap_args *args)
 	mach_thread_abort_request_t *req = args->smsg;
 	mach_thread_abort_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 
 	lwp_exit(tl);
 
@@ -454,7 +453,7 @@ mach_thread_set_policy(struct mach_trap_args *args)
 	mach_thread_set_policy_request_t *req = args->smsg;
 	mach_thread_set_policy_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	mach_port_t mn;
 	struct mach_right *mr;
 	int limit_count_offset, limit_offset;
diff --git a/sys/compat/mach/mach_thread.h b/sys/compat/mach/mach_thread.h
index 9a10ebb..30ef758 100644
--- a/sys/compat/mach/mach_thread.h
+++ b/sys/compat/mach/mach_thread.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_thread.h,v 1.19 2008/04/28 20:23:44 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -42,8 +42,8 @@
 
 /* For mach_create_thread_child() */
 struct mach_create_thread_child_args {
-	struct lwp *mctc_lwp;
-	struct lwp *mctc_oldlwp;
+	struct thread *mctc_lwp;
+	struct thread *mctc_oldlwp;
 	mach_natural_t *mctc_state;
 	int mctc_flavor;
 	int mctc_child_done;
@@ -242,8 +242,8 @@ typedef struct {
 } mach_thread_set_policy_reply_t;
 
 /* These are machine dependent functions */
-int mach_thread_get_state_machdep(struct lwp *, int, void *, int *);
-int mach_thread_set_state_machdep(struct lwp *, int, void *);
+int mach_thread_get_state_machdep(struct thread *, int, void *, int *);
+int mach_thread_set_state_machdep(struct thread *, int, void *);
 void mach_create_thread_child(void *);
 
 #endif /* _MACH_THREAD_H_ */
diff --git a/sys/compat/mach/mach_types.h b/sys/compat/mach/mach_types.h
index 7a2617b..6ef1603 100644
--- a/sys/compat/mach/mach_types.h
+++ b/sys/compat/mach/mach_types.h
@@ -1,5 +1,4 @@
-/*	$NetBSD: mach_types.h,v 1.24 2008/04/28 20:23:44 martin Exp $	 */
-
+/*	$FreeBSD$ */
 /*-
  * Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,6 +31,10 @@
 #ifndef	_MACH_TYPES_H_
 #define	_MACH_TYPES_H_
 
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+
 typedef int mach_port_t;
 typedef int mach_port_name_t;
 typedef int mach_port_type_t;
@@ -73,6 +76,7 @@ typedef unsigned int mach_vm_machine_attribute_t;
 typedef mach_natural_t mach_port_urefs_t;
 typedef int mach_port_delta_t;
 
+MALLOC_DECLARE(M_MACH);
 
 /*
  * This is called cproc_t in Mach (cthread_t in Darwin). It is a pointer to
diff --git a/sys/compat/mach/mach_vm.c b/sys/compat/mach/mach_vm.c
index b495add..aeb3588 100644
--- a/sys/compat/mach/mach_vm.c
+++ b/sys/compat/mach/mach_vm.c
@@ -1,5 +1,3 @@
-/*	$NetBSD: mach_vm.c,v 1.62 2010/06/24 13:03:07 hannken Exp $ */
-
 /*-
  * Copyright (c) 2002-2003, 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.62 2010/06/24 13:03:07 hannken Exp $");
+__FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -44,11 +42,11 @@ __KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.62 2010/06/24 13:03:07 hannken Exp $")
 #include <sys/filedesc.h>
 #include <sys/ktrace.h>
 #include <sys/exec.h>
-#include <sys/syscallargs.h>
+#include <sys/sysproto.h>
 
-#include <uvm/uvm_prot.h>
-#include <uvm/uvm_map.h>
-#include <uvm/uvm_extern.h>
+#include <vm/pmap.h>
+#include <vm/vm_map.h>
+#include <vm/vm_extern.h>
 
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
@@ -57,7 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.62 2010/06/24 13:03:07 hannken Exp $")
 #include <compat/mach/mach_errno.h>
 #include <compat/mach/mach_port.h>
 #include <compat/mach/mach_services.h>
-#include <compat/mach/mach_syscallargs.h>
+#include <compat/mach/mach_proto.h>
 
 int
 mach_vm_map(struct mach_trap_args *args)
@@ -65,10 +63,10 @@ mach_vm_map(struct mach_trap_args *args)
 	mach_vm_map_request_t *req = args->smsg;
 	mach_vm_map_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
-	struct proc *tp = tl->l_proc;
+	struct thread *ttd = args->ttd;
+	struct proc *tp = ttd->td_proc;
 	struct sys_mmap_args cup;
-	vaddr_t addr;
+	vm_offset_t addr;
 	int error, flags;
 	void *ret;
 
@@ -95,10 +93,10 @@ mach_vm_map(struct mach_trap_args *args)
 		req->req_mask += 1;
 
 	if (req->req_flags & MACH_VM_FLAGS_ANYWHERE) {
-		SCARG(&cup, flags) = MAP_ANON;
+		cup.flags = MAP_ANON;
 		flags = 0;
 	} else {
-		SCARG(&cup, flags) = MAP_ANON | MAP_FIXED;
+		cup.flags = MAP_ANON | MAP_FIXED;
 		flags = MAP_FIXED;
 	}
 
@@ -107,7 +105,7 @@ mach_vm_map(struct mach_trap_args *args)
 	 * requested alignement.
 	 */
 	vm_map_lock(&tp->p_vmspace->vm_map);
-	ret = uvm_map_findspace(&tp->p_vmspace->vm_map,
+	ret = vm_map_findspace(&tp->p_vmspace->vm_map,
 	    trunc_page(req->req_address), req->req_size, &addr,
 	    NULL, 0, req->req_mask, flags);
 	vm_map_unlock(&tp->p_vmspace->vm_map);
@@ -117,27 +115,27 @@ mach_vm_map(struct mach_trap_args *args)
 
 	switch(req->req_inherance) {
 	case MACH_VM_INHERIT_SHARE:
-		SCARG(&cup, flags) |= MAP_INHERIT;
+		cup.flags |= MAP_INHERIT_SHARE;
 		break;
 	case MACH_VM_INHERIT_COPY:
-		SCARG(&cup, flags) |= MAP_COPY;
+		cup.flags) |= MAP_COPY_ON_WRITE;
 		break;
 	case MACH_VM_INHERIT_NONE:
 		break;
 	case MACH_VM_INHERIT_DONATE_COPY:
 	default:
-		uprintf("mach_vm_map: unsupported inherance flag %d\n",
+		uprintf("mach_vm_map: unsupported inheritance flag %d\n",
 		    req->req_inherance);
 		break;
 	}
 
-	SCARG(&cup, addr) = (void *)addr;
-	SCARG(&cup, len) = req->req_size;
-	SCARG(&cup, prot) = req->req_cur_protection;
-	SCARG(&cup, fd) = -1;		/* XXX For now, no object mapping */
-	SCARG(&cup, pos) = req->req_offset;
+	cup.addr) = (void *)addr;
+	cup.len) = req->req_size;
+	cup.prot) = req->req_cur_protection;
+	cup.fd) = -1;		/* XXX For now, no object mapping */
+	cup.pos) = req->req_offset;
 
-	if ((error = sys_mmap(tl, &cup, &rep->rep_retval)) != 0)
+	if ((error = sys_mmap(ttd, &cup, &rep->rep_retval)) != 0)
 		return mach_msg_error(args, error);
 
 	*msglen = sizeof(*rep);
@@ -153,10 +151,10 @@ mach_vm_allocate(struct mach_trap_args *args)
 	mach_vm_allocate_request_t *req = args->smsg;
 	mach_vm_allocate_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
-	struct proc *tp = tl->l_proc;
+	struct thread *ttd = args->ttd;
+	struct proc *tp = ttd->td_proc;
 	struct sys_mmap_args cup;
-	vaddr_t addr;
+	vm_offset_t addr;
 	size_t size;
 	int error;
 
@@ -195,16 +193,16 @@ mach_vm_allocate(struct mach_trap_args *args)
 	if (size == 0)
 		goto out;
 
-	SCARG(&cup, addr) = (void *)addr;
-	SCARG(&cup, len) = size;
-	SCARG(&cup, prot) = PROT_READ | PROT_WRITE;
-	SCARG(&cup, flags) = MAP_ANON;
+	cup.addr) = (void *)addr;
+	cup.len) = size;
+	cup.prot) = PROT_READ | PROT_WRITE;
+	cup.flags) = MAP_ANON;
 	if ((req->req_flags & MACH_VM_FLAGS_ANYWHERE) == 0)
-		SCARG(&cup, flags) |= MAP_FIXED;
-	SCARG(&cup, fd) = -1;
-	SCARG(&cup, pos) = 0;
+		cup.flags) |= MAP_FIXED;
+	cup.fd) = -1;
+	cup.pos) = 0;
 
-	if ((error = sys_mmap(tl, &cup, &rep->rep_address)) != 0)
+	if ((error = sys_mmap(ttd, &cup, &rep->rep_address)) != 0)
 		return mach_msg_error(args, error);
 #ifdef DEBUG_MACH_VM
 	printf("vm_allocate: success at %p\n", (void *)rep->rep_address);
@@ -227,7 +225,7 @@ mach_vm_deallocate(struct mach_trap_args *args)
 	mach_vm_deallocate_request_t *req = args->smsg;
 	mach_vm_deallocate_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	struct sys_munmap_args cup;
 	int error;
 
@@ -236,10 +234,10 @@ mach_vm_deallocate(struct mach_trap_args *args)
 	    (void *)req->req_address, (long)req->req_size);
 #endif
 
-	SCARG(&cup, addr) = (void *)req->req_address;
-	SCARG(&cup, len) = req->req_size;
+	cup.addr) = (void *)req->req_address;
+	cup.len) = req->req_size;
 
-	if ((error = sys_munmap(tl, &cup, &rep->rep_retval)) != 0)
+	if ((error = sys_munmap(ttd, &cup, &rep->rep_retval)) != 0)
 		return mach_msg_error(args, error);
 
 	*msglen = sizeof(*rep);
@@ -260,7 +258,7 @@ mach_vm_wire(struct mach_trap_args *args)
 	mach_vm_wire_request_t *req = args->smsg;
 	mach_vm_wire_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	register_t retval;
 	int error;
 
@@ -281,20 +279,20 @@ mach_vm_wire(struct mach_trap_args *args)
 	if (req->req_access == 0) {
 		struct sys_munlock_args cup;
 
-		SCARG(&cup, addr) = (void *)req->req_address;
-		SCARG(&cup, len) = req->req_size;
-		error = sys_munlock(tl, &cup, &retval);
+		cup.addr) = (void *)req->req_address;
+		cup.len) = req->req_size;
+		error = sys_munlock(ttd, &cup, &retval);
 	} else {
 		struct sys_mlock_args cup;
 
-		SCARG(&cup, addr) = (void *)req->req_address;
-		SCARG(&cup, len) = req->req_size;
-		error = sys_mlock(tl, &cup, &retval);
+		cup.addr) = (void *)req->req_address;
+		cup.len) = req->req_size;
+		error = sys_mlock(ttd, &cup, &retval);
 	}
 	if (error != 0)
 		return mach_msg_error(args, error);
 
-	if ((error = uvm_map_protect(&tl->l_proc->p_vmspace->vm_map,
+	if ((error = vm_map_protect(&ttd->td_proc->p_vmspace->vm_map,
 	    req->req_address, req->req_address + req->req_size,
 	    req->req_access, 0)) != 0)
 		return mach_msg_error(args, error);
@@ -313,16 +311,16 @@ mach_vm_protect(struct mach_trap_args *args)
 	mach_vm_protect_request_t *req = args->smsg;
 	mach_vm_protect_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	struct sys_mprotect_args cup;
 	register_t retval;
 	int error;
 
-	SCARG(&cup, addr) = (void *)req->req_addr;
-	SCARG(&cup, len) = req->req_size;
-	SCARG(&cup, prot) = req->req_prot;
+	cup.addr) = (void *)req->req_addr;
+	cup.len) = req->req_size;
+	cup.prot) = req->req_prot;
 
-	if ((error = sys_mprotect(tl, &cup, &retval)) != 0)
+	if ((error = sys_mprotect(ttd, &cup, &retval)) != 0)
 		return mach_msg_error(args, error);
 
 	*msglen = sizeof(*rep);
@@ -333,7 +331,7 @@ mach_vm_protect(struct mach_trap_args *args)
 }
 
 int
-mach_sys_map_fd(struct lwp *l, const struct mach_sys_map_fd_args *uap, register_t *retval)
+mach_sys_map_fd(struct thread *td, const struct mach_sys_map_fd_args *uap)
 {
 	/* {
 		syscallarg(int) fd;
@@ -346,23 +344,23 @@ mach_sys_map_fd(struct lwp *l, const struct mach_sys_map_fd_args *uap, register_
 	struct vnode *vp;
 	struct exec_vmcmd evc;
 	struct vm_map_entry *ret;
-	struct proc *p = l->l_proc;
+	struct proc *p = td->td_proc;
 	register_t dontcare;
 	struct sys_munmap_args cup;
 	void *va;
 	int error;
 
-	if ((error = copyin(SCARG(uap, va), (void *)&va, sizeof(va))) != 0)
+	if ((error = copyin(uap->va, (void *)&va, sizeof(va))) != 0)
 		return error;
 
-	if (SCARG(uap, findspace) == 0) {
+	if (uap->findspace == 0) {
 		/* Make some free space XXX probably not The Right Way */
-		SCARG(&cup, addr) = va;
-		SCARG(&cup, len) = SCARG(uap, size);
-		(void)sys_munmap(l, &cup, &dontcare);
+		cup.addr = va;
+		cup.len = uap->size;
+		(void)sys_munmap(td, &cup, &dontcare);
 	}
 
-	fp = fd_getfile(SCARG(uap, fd));
+	fp = fd_getfile(uap->fd);
 	if (fp == NULL)
 		return EBADF;
 
@@ -371,32 +369,32 @@ mach_sys_map_fd(struct lwp *l, const struct mach_sys_map_fd_args *uap, register_
 
 #ifdef DEBUG_MACH_VM
 	printf("vm_map_fd: addr = %p len = 0x%08lx\n",
-	    va, (long)SCARG(uap, size));
+		   va, (long)uap->size);
 #endif
 	memset(&evc, 0, sizeof(evc));
 	evc.ev_addr = (u_long)va;
-	evc.ev_len = SCARG(uap, size);
+	evc.ev_len = uap->size;
 	evc.ev_prot = VM_PROT_ALL;
-	evc.ev_flags = SCARG(uap, findspace) ? 0 : VMCMD_FIXED;
+	evc.ev_flags = uap->findspace ? 0 : VMCMD_FIXED;
 	evc.ev_proc = vmcmd_map_readvn;
-	evc.ev_offset = SCARG(uap, offset);
+	evc.ev_offset = uap->offset;
 	evc.ev_vp = vp;
 
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-	if ((error = (*evc.ev_proc)(l, &evc)) != 0) {
+	if ((error = (*evc.ev_proc)(td, &evc)) != 0) {
 		VOP_UNLOCK(vp);
 
 #ifdef DEBUG_MACH_VM
 		printf("mach_sys_map_fd: mapping at %p failed\n", va);
 #endif
 
-		if (SCARG(uap, findspace) == 0)
+		if (uap->findspace == 0)
 			goto bad2;
 
 		vm_map_lock(&p->p_vmspace->vm_map);
-		if ((ret = uvm_map_findspace(&p->p_vmspace->vm_map,
+		if ((ret = vm_map_findspace(&p->p_vmspace->vm_map,
 		    vm_map_min(&p->p_vmspace->vm_map), evc.ev_len,
-		    (vaddr_t *)&evc.ev_addr, NULL, 0, PAGE_SIZE, 0)) == NULL) {
+		    (vm_offset_t *)&evc.ev_addr, NULL, 0, PAGE_SIZE, 0)) == NULL) {
 			vm_map_unlock(&p->p_vmspace->vm_map);
 			goto bad2;
 		}
@@ -406,30 +404,30 @@ mach_sys_map_fd(struct lwp *l, const struct mach_sys_map_fd_args *uap, register_
 
 		memset(&evc, 0, sizeof(evc));
 		evc.ev_addr = (u_long)va;
-		evc.ev_len = SCARG(uap, size);
+		evc.ev_len = uap->size;
 		evc.ev_prot = VM_PROT_ALL;
 		evc.ev_flags = 0;
 		evc.ev_proc = vmcmd_map_readvn;
-		evc.ev_offset = SCARG(uap, offset);
+		evc.ev_offset = uap->offset;
 		evc.ev_vp = vp;
 
 #ifdef DEBUG_MACH_VM
 		printf("mach_sys_map_fd: trying at %p\n", va);
 #endif
 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-		if ((error = (*evc.ev_proc)(l, &evc)) != 0)
+		if ((error = (*evc.ev_proc)(td, &evc)) != 0)
 			goto bad1;
 	}
 
 	vput(vp);
-	fd_putfile(SCARG(uap, fd));
+	fd_putfile(uap->fd);
 #ifdef DEBUG_MACH_VM
 	printf("mach_sys_map_fd: mapping at %p\n", (void *)evc.ev_addr);
 #endif
 
 	va = (mach_vm_offset_t *)evc.ev_addr;
 
-	if ((error = copyout((void *)&va, SCARG(uap, va), sizeof(va))) != 0)
+	if ((error = copyout((void *)&va, uap->va, sizeof(va))) != 0)
 		return error;
 
 	return 0;
@@ -438,7 +436,7 @@ bad1:
 	VOP_UNLOCK(vp);
 bad2:
 	vrele(vp);
-	fd_putfile(SCARG(uap, fd));
+	fd_putfile(uap->fd);
 #ifdef DEBUG_MACH_VM
 	printf("mach_sys_map_fd: mapping at %p failed, error = %d\n",
 	    (void *)evc.ev_addr, error);
@@ -452,17 +450,17 @@ mach_vm_inherit(struct mach_trap_args *args)
 	mach_vm_inherit_request_t *req = args->smsg;
 	mach_vm_inherit_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	struct sys_minherit_args cup;
 	register_t retval;
 	int error;
 
-	SCARG(&cup, addr) = (void *)req->req_addr;
-	SCARG(&cup, len) = req->req_size;
+	cup.addr) = (void *)req->req_addr;
+	cup.len) = req->req_size;
 	/* Flags map well between Mach and NetBSD */
-	SCARG(&cup, inherit) = req->req_inh;
+	cup.inherit) = req->req_inh;
 
-	if ((error = sys_minherit(tl, &cup, &retval)) != 0)
+	if ((error = sys_minherit(ttd, &cup, &retval)) != 0)
 		return mach_msg_error(args, error);
 
 	*msglen = sizeof(*rep);
@@ -478,8 +476,8 @@ mach_make_memory_entry_64(struct mach_trap_args *args)
 	mach_make_memory_entry_64_request_t *req = args->smsg;
 	mach_make_memory_entry_64_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
-	struct lwp *tl = args->tl;
+	struct thread *td = args->td;
+	struct thread *ttd = args->ttd;
 	struct mach_port *mp;
 	struct mach_right *mr;
 	struct mach_memory_entry *mme;
@@ -491,13 +489,13 @@ mach_make_memory_entry_64(struct mach_trap_args *args)
 	mp->mp_flags |= (MACH_MP_INKERNEL | MACH_MP_DATA_ALLOCATED);
 	mp->mp_datatype = MACH_MP_MEMORY_ENTRY;
 
-	mme = malloc(sizeof(*mme), M_EMULDATA, M_WAITOK);
-	mme->mme_proc = tl->l_proc;
+	mme = malloc(sizeof(*mme), M_MACH, M_WAITOK);
+	mme->mme_proc = td->td_proc;
 	mme->mme_offset = req->req_offset;
 	mme->mme_size = req->req_size;
 	mp->mp_data = mme;
 
-	mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
+	mr = mach_right_get(mp, td, MACH_PORT_TYPE_SEND, 0);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
@@ -516,7 +514,7 @@ mach_vm_region(struct mach_trap_args *args)
 	mach_vm_region_request_t *req = args->smsg;
 	mach_vm_region_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	struct mach_vm_region_basic_info *rbi;
 	struct vm_map *map;
 	struct vm_map_entry *vme;
@@ -536,10 +534,10 @@ mach_vm_region(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 	*msglen = sizeof(*rep) + ((req->req_count - 9) * sizeof(int));
 
-	map = &tl->l_proc->p_vmspace->vm_map;
+	map = &td->td_proc->p_vmspace->vm_map;
 
 	vm_map_lock(map);
-	error = uvm_map_lookup_entry(map, req->req_addr, &vme);
+	error = vm_map_lookup_entry(map, req->req_addr, &vme);
 	vm_map_unlock(map);
 
 	if (error == 0)
@@ -574,7 +572,7 @@ mach_vm_region_64(struct mach_trap_args *args)
 	mach_vm_region_64_request_t *req = args->smsg;
 	mach_vm_region_64_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	struct mach_vm_region_basic_info_64 *rbi;
 	struct vm_map *map;
 	struct vm_map_entry *vme;
@@ -594,10 +592,10 @@ mach_vm_region_64(struct mach_trap_args *args)
 		return mach_msg_error(args, EINVAL);
 	*msglen = sizeof(*rep) + ((req->req_count - 9) * sizeof(int));
 
-	map = &tl->l_proc->p_vmspace->vm_map;
+	map = &td->td_proc->p_vmspace->vm_map;
 
 	vm_map_lock(map);
-	error = uvm_map_lookup_entry(map, req->req_addr, &vme);
+	error = vm_map_lookup_entry(map, req->req_addr, &vme);
 	vm_map_unlock(map);
 
 	if (error == 0)
@@ -631,22 +629,22 @@ mach_vm_msync(struct mach_trap_args *args)
 	mach_vm_msync_request_t *req = args->smsg;
 	mach_vm_msync_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	struct sys___msync13_args cup;
 	int error;
 	register_t dontcare;
 
-	SCARG(&cup, addr) = (void *)req->req_addr;
-	SCARG(&cup, len) = req->req_size;
-	SCARG(&cup, flags) = 0;
+	cup.addr = (void *)req->req_addr;
+	cup.len = req->req_size;
+	cup.flags = 0;
 	if (req->req_flags & MACH_VM_SYNC_ASYNCHRONOUS)
-		SCARG(&cup, flags) |= MS_ASYNC;
+		cup.flags |= MS_ASYNC;
 	if (req->req_flags & MACH_VM_SYNC_SYNCHRONOUS)
-		SCARG(&cup, flags) |= MS_SYNC;
+		cup.flags |= MS_SYNC;
 	if (req->req_flags & MACH_VM_SYNC_INVALIDATE)
-		SCARG(&cup, flags) |= MS_INVALIDATE;
+		cup.flags |= MS_INVALIDATE;
 
-	error = sys___msync13(tl, &cup, &dontcare);
+	error = sys___msync13(ttd, &cup, &dontcare);
 
 	*msglen = sizeof(*rep);
 	mach_set_header(rep, req, *msglen);
@@ -719,17 +717,17 @@ mach_vm_read(struct mach_trap_args *args)
 	mach_vm_read_request_t *req = args->smsg;
 	mach_vm_read_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *l = args->l;
-	struct lwp *tl = args->tl;
+	struct thread *td = args->td;
+	struct thread *ttd = args->ttd;
 	char *tbuf;
 	void *addr;
-	vaddr_t va;
+	vm_offset_t va;
 	size_t size;
 	int error;
 
 	size = req->req_size;
-	va = vm_map_min(&l->l_proc->p_vmspace->vm_map);
-	if ((error = uvm_map(&l->l_proc->p_vmspace->vm_map, &va,
+	va = vm_map_min(&td->td_proc->p_vmspace->vm_map);
+	if ((error = vm_map(&td->td_proc->p_vmspace->vm_map, &va,
 	    round_page(size), NULL, UVM_UNKNOWN_OFFSET, 0,
 	    UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_ALL,
 	    UVM_INH_COPY, UVM_ADV_NORMAL, UVM_FLAG_COPYONW))) != 0) {
@@ -742,10 +740,10 @@ mach_vm_read(struct mach_trap_args *args)
 	 * This is reasonable for small chunk of data, but we should
 	 * remap COW for areas bigger than a page.
 	 */
-	tbuf = malloc(size, M_EMULDATA, M_WAITOK);
+	tbuf = malloc(size, M_MACH, M_WAITOK);
 
 	addr = (void *)req->req_addr;
-	if ((error = copyin_proc(tl->l_proc, addr, tbuf, size)) != 0) {
+	if ((error = copyin_proc(td->td_proc, addr, tbuf, size)) != 0) {
 		printf("copyin_proc error = %d, addr = %p, size = %x\n", error, addr, size);
 		free(tbuf, M_WAITOK);
 		return mach_msg_error(args, EFAULT);
@@ -779,7 +777,7 @@ mach_vm_write(struct mach_trap_args *args)
 	mach_vm_write_request_t *req = args->smsg;
 	mach_vm_write_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	size_t size;
 	void *addr;
 	char *tbuf;
@@ -796,7 +794,7 @@ mach_vm_write(struct mach_trap_args *args)
 	 * remap COW for areas bigger than a page.
 	 */
 	size = req->req_data.size;
-	tbuf = malloc(size, M_EMULDATA, M_WAITOK);
+	tbuf = malloc(size, M_MACH, M_WAITOK);
 
 	if ((error = copyin(req->req_data.address, tbuf, size)) != 0) {
 		printf("copyin error = %d\n", error);
@@ -805,7 +803,7 @@ mach_vm_write(struct mach_trap_args *args)
 	}
 
 	addr = (void *)req->req_addr;
-	if ((error = copyout_proc(tl->l_proc, tbuf, addr, size)) != 0) {
+	if ((error = copyout_proc(td->td_proc, tbuf, addr, size)) != 0) {
 		printf("copyout_proc error = %d\n", error);
 		free(tbuf, M_WAITOK);
 		return mach_msg_error(args, EFAULT);
@@ -832,7 +830,7 @@ mach_vm_machine_attribute(struct mach_trap_args *args)
 	mach_vm_machine_attribute_request_t *req = args->smsg;
 	mach_vm_machine_attribute_reply_t *rep = args->rmsg;
 	size_t *msglen = args->rsize;
-	struct lwp *tl = args->tl;
+	struct thread *ttd = args->ttd;
 	int error = 0;
 	int attribute, value;
 
@@ -846,7 +844,7 @@ mach_vm_machine_attribute(struct mach_trap_args *args)
 		case MACH_MATTR_VAL_DCACHE_FLUSH:
 		case MACH_MATTR_VAL_ICACHE_FLUSH:
 		case MACH_MATTR_VAL_CACHE_SYNC:
-			error = mach_vm_machine_attribute_machdep(tl,
+			error = mach_vm_machine_attribute_machdep(ttd,
 			    req->req_addr, req->req_size, &value);
 			break;
 		default:
diff --git a/sys/compat/mach/mach_vm.h b/sys/compat/mach/mach_vm.h
index 0c887d9..8f277f7 100644
--- a/sys/compat/mach/mach_vm.h
+++ b/sys/compat/mach/mach_vm.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: mach_vm.h,v 1.30 2008/04/28 20:23:45 martin Exp $ */
+/*	$FreeBSD$ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -381,11 +381,11 @@ typedef struct {
 
 struct mach_memory_entry {
 	struct proc *mme_proc;
-	vaddr_t	mme_offset;
+	vm_offset_t	mme_offset;
 	size_t mme_size;
 };
 
 /* These are machine dependent functions */
-int mach_vm_machine_attribute_machdep(struct lwp *, vaddr_t, size_t, int *);
+int mach_vm_machine_attribute_machdep(struct td *, vm_offset_t, size_t, int *);
 
 #endif /* _MACH_VM_H_ */
diff --git a/sys/compat/mach/makemachservices.sh b/sys/compat/mach/makemachservices.sh
index 34c2be6..005eace 100755
--- a/sys/compat/mach/makemachservices.sh
+++ b/sys/compat/mach/makemachservices.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-#	$NetBSD: makemachservices.sh,v 1.8 2008/05/04 00:43:55 martin Exp $
+#	$FreeBSD$
 #
 # Copyright (c) 2003 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -47,17 +47,17 @@ BEGIN{
 	headers = "'$headers'";
 	names = "'$names'";
 
-	printf("/* \$NetBSD\$ *\/\n\n") > table;
+	printf("/* \$FreeBSD\$ *\/\n\n") > table;
 	printf("/*\n * Mach services table.\n *\n") > table;
 	printf(" * DO NOT EDIT -- this file is automatically generated.\n") > \
 	    table;
 
-	printf("/* \$NetBSD\$ *\/\n\n") > headers;
+	printf("/* \$FreeBSD\$ *\/\n\n") > headers;
 	printf("/*\n * Mach services prototypes.\n *\n") > headers;
 	printf(" * DO NOT EDIT -- this file is automatically generated.\n") > \
 	    headers;
 
-	printf("/* \$NetBSD\$ *\/\n\n") > names;
+	printf("/* \$FreeBSD\$ *\/\n\n") > names;
 	printf("/*\n * Mach services names. This file is not built\n") > names;
 	printf(" * by the kernel, it is included by kdump sources.\n *\n") > \
 	    names;
@@ -69,18 +69,18 @@ BEGIN{
 	gsub(/\$.*$/, "", $0);
 	sub(/ $/, "");
 	printf(" * created from %s\n */\n\n", $0) > table;
-	printf("#include \<sys/cdefs.h\>\n__KERNEL_RCSID(0, " \
-	    "\"\$NetBSD\$\");\n\n") > table;
+	printf("#include \<sys/cdefs.h\>\n__FBSDID(0, " \
+	    "\"\$FreeBSD\$\");\n\n") > table;
 
 	printf(" * created from %s\n */\n\n", $0) > headers;
-	printf("#include \<sys/cdefs.h\>\n__KERNEL_RCSID(0, " \
-	    "\"\$NetBSD\$\");\n\n") > headers;
+	printf("#include \<sys/cdefs.h\>\n__FBSDID(0, " \
+	    "\"\$FreeBSD\$\");\n\n") > headers;
 	printf("#include <compat/mach/mach_types.h>\n") > headers;
 	printf("#include <compat/mach/mach_message.h>\n") > headers;
 
 	printf(" * created from %s\n */\n\n", $0) > names;
-	printf("#include \<sys/cdefs.h\>\n__KERNEL_RCSID(0, " \
-	    "\"\$NetBSD\$\");\n\n") > names;
+	printf("#include \<sys/cdefs.h\>\n__FBSDID(0, " \
+	    "\"\$FreeBSD\$\");\n\n") > names;
 	printf("struct mach_service_name {\n") > names;
 	printf("	int srv_id;\n") > names;
 	printf("	const char *srv_name;\n") > names;
diff --git a/sys/compat/mach/syscalls.c b/sys/compat/mach/syscalls.c
new file mode 100644
index 0000000..70639e0
--- /dev/null
+++ b/sys/compat/mach/syscalls.c
@@ -0,0 +1,5 @@
+/*
+ * System call names.
+ *
+ * DO NOT EDIT-- this file is automatically generated.
+ * $FreeBSD$
diff --git a/sys/compat/mach/syscalls.conf b/sys/compat/mach/syscalls.conf
index c416d08..86dfb98f 100644
--- a/sys/compat/mach/syscalls.conf
+++ b/sys/compat/mach/syscalls.conf
@@ -1,14 +1,18 @@
-#	$NetBSD: syscalls.conf,v 1.2 2007/12/10 22:32:15 dsl Exp $
+#	$FreeBSD$
 
 sysnames="mach_syscalls.c"
-sysnumhdr="mach_syscall.h"
+sysproto="mach_proto.h"
+sysproto_h=_MACH_SYSPROTO_H_
+syshdr="mach_syscall.h"
 syssw="mach_sysent.c"
-sysarghdr="mach_syscallargs.h"
+sysmk="/dev/null"
+syscallprefix="MACH_SYS_"
 compatopts=""
 libcompatopts=""
 
 switchname="mach_sysent"
 namesname="mach_syscallnames"
+systracte="mach_systrace_args.c"
 constprefix="MACH_SYS_"
 nsysent=128
 maxsysargs=9
diff --git a/sys/compat/mach/syscalls.master b/sys/compat/mach/syscalls.master
index 001a094..9a0433e 100644
--- a/sys/compat/mach/syscalls.master
+++ b/sys/compat/mach/syscalls.master
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.10 2009/01/13 22:27:43 pooka Exp $
+	$FreeBSD$
 
 ;	@(#)syscalls.master	8.1 (Berkeley) 7/19/93
 
@@ -34,7 +34,6 @@
 
 #if defined(_KERNEL_OPT)
 #include "opt_ntp.h"
-#include "opt_sysv.h"
 #endif
 
 #include <sys/param.h>
@@ -42,54 +41,54 @@
 #include <sys/signal.h>
 #include <sys/mount.h>
 #include <sys/poll.h>
-#include <sys/syscallargs.h>
+#include <sys/sysent.h>
+#include <sys/sysproto.h>
 
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
 #include <compat/mach/mach_clock.h>
-#include <compat/mach/mach_syscallargs.h>
-%%
+#include <compat/mach/mach_proto.h>
+;;
 
-0	UNIMPL
-1	UNIMPL
-2	UNIMPL
-3	UNIMPL
-4	UNIMPL
-5	UNIMPL
-6	UNIMPL
-7	UNIMPL
-8	UNIMPL
-9	UNIMPL
-10	UNIMPL
-11	UNIMPL
-12	UNIMPL
-13	UNIMPL
-14	UNIMPL
-15	UNIMPL
-16	UNIMPL
-17	UNIMPL
-18	UNIMPL
-19	UNIMPL
-20	UNIMPL
-21	UNIMPL
-22	UNIMPL
-23	UNIMPL
-24	UNIMPL
-25	UNIMPL
-26	STD		{ mach_port_name_t|mach_sys||reply_port(void); }
-27	STD		{ mach_port_name_t|mach_sys||thread_self_trap(void); }
-28	STD		{ mach_port_name_t|mach_sys||task_self_trap(void); }
-29	STD		{ mach_port_name_t|mach_sys||host_self_trap(void); }
-30	UNIMPL
-31	STD		{ mach_msg_return_t|mach_sys||msg_trap( \
-			    mach_msg_header_t	*msg, \
+0  AUE_NULL	UNIMPL	nosys
+1  AUE_NULL	UNIMPL	nosys
+2  AUE_NULL	UNIMPL	nosys
+3  AUE_NULL	UNIMPL	nosys
+4  AUE_NULL	UNIMPL	nosys
+5  AUE_NULL	UNIMPL	nosys
+6  AUE_NULL	UNIMPL	nosys
+7  AUE_NULL	UNIMPL	nosys
+8  AUE_NULL	UNIMPL	nosys
+9  AUE_NULL	UNIMPL	nosys
+10  AUE_NULL	UNIMPL	nosys
+11  AUE_NULL	UNIMPL	nosys
+12  AUE_NULL	UNIMPL	nosys
+13  AUE_NULL	UNIMPL	nosys
+14  AUE_NULL	UNIMPL	nosys
+15  AUE_NULL	UNIMPL	nosys
+16  AUE_NULL	UNIMPL	nosys
+17  AUE_NULL	UNIMPL	nosys
+18  AUE_NULL	UNIMPL	nosys
+19  AUE_NULL	UNIMPL	nosys
+20  AUE_NULL	UNIMPL	nosys
+21  AUE_NULL	UNIMPL	nosys
+22  AUE_NULL	UNIMPL	nosys
+23  AUE_NULL	UNIMPL	nosys
+24  AUE_NULL	UNIMPL	nosys
+25  AUE_NULL	UNIMPL	nosys
+26	AUE_NULL	STD		{ int mach_reply_port(void); }
+27	AUE_NULL	STD		{ int mach_thread_self_trap(void); }
+28	AUE_NULL	STD		{ int mach_task_self_trap(void); }
+29	AUE_NULL	STD		{ int mach_host_self_trap(void); }
+30  AUE_NULL	UNIMPL	nosys
+31	AUE_NULL	STD		{ int mach_msg_trap(mach_msg_header_t	*msg, \
 			    mach_msg_option_t	option, \
 			    mach_msg_size_t	send_size, \
 			    mach_msg_size_t	rcv_size, \
 			    mach_port_name_t	rcv_name, \
 			    mach_msg_timeout_t	timeout, \
 			    mach_port_name_t	notify); }
-32	STD		{ mach_kern_return_t|mach_sys||msg_overwrite_trap( \
+32	AUE_NULL	STD		{ int mach_msg_overwrite_trap( \
 			    mach_msg_header_t	*msg, \
 			    mach_msg_option_t	option, \
 			    mach_msg_size_t	send_size, \
@@ -99,143 +98,129 @@
 			    mach_port_name_t	notify, \
 			    mach_msg_header_t	*rcv_msg, \
 			    mach_msg_size_t	scatter_list_size); }
-33	STD		{ mach_kern_return_t|\
-			    mach_sys||semaphore_signal_trap( \
-			    mach_port_name_t signal_name); }
-34	STD		{ mach_kern_return_t|\
-			    mach_sys||semaphore_signal_all_trap( \
-			    mach_port_name_t signal_name); }
-35	STD		{ mach_kern_return_t|\
-			    mach_sys||semaphore_signal_thread_trap( \
-			    mach_port_name_t signal_name, \
-			    mach_port_name_t thread); }
-36	STD		{ mach_kern_return_t|\
-			    mach_sys||semaphore_wait_trap( \
-			    mach_port_name_t wait_name); }
-37	STD		{ mach_kern_return_t|\
-			    mach_sys||semaphore_wait_signal_trap( \
-			    mach_port_name_t wait_name, \
-			    mach_port_name_t signal_name); }
-38	STD		{ mach_kern_return_t|\
-			    mach_sys||semaphore_timedwait_trap( \
+33	AUE_NULL	STD		{ int mach_semaphore_signal_trap( \
+			  mach_port_name_t signal_name); }
+34	AUE_NULL	STD		{ int mach_semaphore_signal_all_trap( \
+			      mach_port_name_t signal_name); }
+35	AUE_NULL	STD		{ int mach_semaphore_signal_thread_trap( \
+			      	mach_port_name_t signal_name, \
+			    	mach_port_name_t thread); }
+36	AUE_NULL	STD		{ int mach_semaphore_wait_trap( \
+			      mach_port_name_t wait_name); }
+37	AUE_NULL	STD		{ int mach_semaphore_wait_signal_trap( \
+			      mach_port_name_t wait_name, \
+			      mach_port_name_t signal_name); }
+38	AUE_NULL	STD		{ int mach_semaphore_timedwait_trap( \
 			    mach_port_name_t wait_name, \
 			    unsigned int sec, \
 			    mach_clock_res_t nsec); }
-39	STD		{ mach_kern_return_t|\
-			    mach_sys||semaphore_timedwait_signal_trap( \
+39	AUE_NULL	STD		{ int mach_semaphore_timedwait_signal_trap( \
 			    mach_port_name_t wait_name, \
 			    mach_port_name_t signal_name, \
 			    unsigned int sec, \
 			    mach_clock_res_t nsec); }
-40	UNIMPL
-41	STD		{ mach_kern_return_t|mach_sys||init_process(void); }
-42	UNIMPL
-43	STD		{ mach_kern_return_t|mach_sys||map_fd(int fd, \
+40  AUE_NULL	UNIMPL	nosys
+41	AUE_NULL	STD		{ int mach_init_process(void); }
+42  AUE_NULL	UNIMPL	nosys
+43	AUE_NULL	STD		{ int mach_map_fd(int fd, \
 			    mach_vm_offset_t offset, mach_vm_offset_t *va, \
 			    mach_boolean_t findspace, mach_vm_size_t size); }
-44	UNIMPL
-45	STD		{ mach_kern_return_t|mach_sys||task_for_pid( \
+44  AUE_NULL	UNIMPL	nosys
+45	AUE_NULL	STD		{ int mach_task_for_pid( \
 			    mach_port_t target_tport, int pid, \
 			    mach_port_t *t); }
-46	STD		{ mach_kern_return_t|mach_sys||pid_for_task( \
+46	AUE_NULL	STD		{ int mach_pid_for_task( \
 			    mach_port_t t, int *x); }
-47	UNIMPL
-48	STD		{ mach_kern_return_t|mach_sys||macx_swapon( \
+47  AUE_NULL	UNIMPL	nosys
+48	AUE_NULL	STD		{ int mach_macx_swapon( \
 			    char *name, int flags, int size, int priority); }
-49	STD		{ mach_kern_return_t|mach_sys||macx_swapoff( \
+49	AUE_NULL	STD		{ int mach_macx_swapoff( \
 			    char *name, int flags); }
-50	UNIMPL
-51	STD		{ mach_kern_return_t|mach_sys||macx_triggers( \
-			    int hi_water, int low_water, int flags, \
-			    mach_port_t alert_port); }
-52	UNIMPL
-53	UNIMPL
-54	UNIMPL
-55	UNIMPL
-56	UNIMPL
-57	UNIMPL
-58	UNIMPL
-59	STD		{ mach_kern_return_t|mach_sys||swtch_pri( \
-			    int pri); }
-60	STD		{ mach_kern_return_t|mach_sys||swtch(void); }
-61	STD		{ mach_kern_return_t|mach_sys||syscall_thread_switch( \
+50  AUE_NULL	UNIMPL	nosys
+51	AUE_NULL	STD		{ int mach_macx_triggers(int hi_water, int low_water, \
+			  	  int flags, mach_port_t alert_port); }
+52  AUE_NULL	UNIMPL	nosys
+53  AUE_NULL	UNIMPL	nosys
+54  AUE_NULL	UNIMPL	nosys
+55  AUE_NULL	UNIMPL	nosys
+56  AUE_NULL	UNIMPL	nosys
+57  AUE_NULL	UNIMPL	nosys
+58  AUE_NULL	UNIMPL	nosys
+59	AUE_NULL	STD		{ int mach_swtch_pri(int pri); }
+60	AUE_NULL	STD		{ int mach_swtch(void); }
+61	AUE_NULL	STD		{ int mach_syscall_thread_switch( \
 			    mach_port_name_t thread_name, \
 			    int option, \
 			    mach_msg_timeout_t option_time); }
-62	STD		{ mach_kern_return_t|mach_sys||clock_sleep_trap( \
+62	AUE_NULL	STD		{ int mach_clock_sleep_trap( \
 			    mach_port_name_t clock_name, \
 			    mach_sleep_type_t sleep_type, \
 			    int sleep_sec, int sleep_nsec, \
 			    mach_timespec_t *wakeup_time); }
-63	UNIMPL
-64	UNIMPL
-65	UNIMPL
-66	UNIMPL
-67	UNIMPL
-68	UNIMPL
-69	UNIMPL
-70	UNIMPL
-71	UNIMPL
-72	UNIMPL
-73	UNIMPL
-74	UNIMPL
-75	UNIMPL
-76	UNIMPL
-77	UNIMPL
-78	UNIMPL
-79	UNIMPL
-80	UNIMPL
-81	UNIMPL
-82	UNIMPL
-83	UNIMPL
-84	UNIMPL
-85	UNIMPL
-86	UNIMPL
-87	UNIMPL
-88	UNIMPL
-89	STD		{ mach_kern_return_t|mach_sys||timebase_info( \
-			    mach_timebase_info_t info); }
-90	STD		{ mach_kern_return_t|mach_sys||wait_until( \
-			    u_int64_t deadline); }
-91	STD		{ mach_port_name_t|mach_sys||timer_create(void); }
-92	STD		{ mach_kern_return_t|mach_sys||timer_destroy( \
-			    mach_port_name_t name); }
-93	STD		{ mach_kern_return_t|mach_sys||timer_arm( \
-			    mach_port_name_t name, \
-			    mach_absolute_time_t expire_time); }
-94	STD		{ mach_kern_return_t|mach_sys||timer_cancel( \
-			    mach_port_name_t name, \
-			    mach_absolute_time_t *result_time); }
-95	STD		{ mach_kern_return_t|mach_sys||get_time_base_info(void); }
-96	UNIMPL
-97	UNIMPL
-98	UNIMPL
-99	UNIMPL
-100	UNIMPL
-101	UNIMPL
-102	UNIMPL
-103	UNIMPL
-104	UNIMPL
-105	UNIMPL
-106	UNIMPL
-107	UNIMPL
-108	UNIMPL
-109	UNIMPL
-110	UNIMPL
-111	UNIMPL
-112	UNIMPL
-113	UNIMPL
-114	UNIMPL
-115	UNIMPL
-116	UNIMPL
-117	UNIMPL
-118	UNIMPL
-119	UNIMPL
-120	UNIMPL
-121	UNIMPL
-122	UNIMPL
-123	UNIMPL
-124	UNIMPL
-125	UNIMPL
-126	UNIMPL
-127	UNIMPL
+63  AUE_NULL	UNIMPL	nosys
+64  AUE_NULL	UNIMPL	nosys
+65  AUE_NULL	UNIMPL	nosys
+66  AUE_NULL	UNIMPL	nosys
+67  AUE_NULL	UNIMPL	nosys
+68  AUE_NULL	UNIMPL	nosys
+69  AUE_NULL	UNIMPL	nosys
+70  AUE_NULL	UNIMPL	nosys
+71  AUE_NULL	UNIMPL	nosys
+72  AUE_NULL	UNIMPL	nosys
+73  AUE_NULL	UNIMPL	nosys
+74  AUE_NULL	UNIMPL	nosys
+75  AUE_NULL	UNIMPL	nosys
+76  AUE_NULL	UNIMPL	nosys
+77  AUE_NULL	UNIMPL	nosys
+78  AUE_NULL	UNIMPL	nosys
+79  AUE_NULL	UNIMPL	nosys
+80  AUE_NULL	UNIMPL	nosys
+81  AUE_NULL	UNIMPL	nosys
+82  AUE_NULL	UNIMPL	nosys
+83  AUE_NULL	UNIMPL	nosys
+84  AUE_NULL	UNIMPL	nosys
+85  AUE_NULL	UNIMPL	nosys
+86  AUE_NULL	UNIMPL	nosys
+87  AUE_NULL	UNIMPL	nosys
+88  AUE_NULL	UNIMPL	nosys
+89	AUE_NULL	STD		{ int mach_timebase_info(mach_timebase_info_t info); }
+90	AUE_NULL	STD		{ int mach_wait_until(uint64_t deadline); }
+91	AUE_NULL	STD		{ int mach_timer_create(void); }
+92	AUE_NULL	STD		{ int mach_timer_destroy(mach_port_name_t name); }
+93	AUE_NULL	STD		{ int mach_timer_arm(mach_port_name_t name, \
+			      			mach_absolute_time_t expire_time); }
+94	AUE_NULL	STD		{ int mach_timer_cancel(mach_port_name_t name, \
+			    		mach_absolute_time_t *result_time); }
+95	AUE_NULL	STD		{ int mach_get_time_base_info(void); }
+96  AUE_NULL	UNIMPL	nosys
+97  AUE_NULL	UNIMPL	nosys
+98  AUE_NULL	UNIMPL	nosys
+99  AUE_NULL	UNIMPL	nosys
+100  AUE_NULL	UNIMPL	nosys
+101  AUE_NULL	UNIMPL	nosys
+102  AUE_NULL	UNIMPL	nosys
+103  AUE_NULL	UNIMPL	nosys
+104  AUE_NULL	UNIMPL	nosys
+105  AUE_NULL	UNIMPL	nosys
+106  AUE_NULL	UNIMPL	nosys
+107  AUE_NULL	UNIMPL	nosys
+108  AUE_NULL	UNIMPL	nosys
+109  AUE_NULL	UNIMPL	nosys
+110  AUE_NULL	UNIMPL	nosys
+111  AUE_NULL	UNIMPL	nosys
+112  AUE_NULL	UNIMPL	nosys
+113  AUE_NULL	UNIMPL	nosys
+114  AUE_NULL	UNIMPL	nosys
+115  AUE_NULL	UNIMPL	nosys
+116  AUE_NULL	UNIMPL	nosys
+117  AUE_NULL	UNIMPL	nosys
+118  AUE_NULL	UNIMPL	nosys
+119  AUE_NULL	UNIMPL	nosys
+120  AUE_NULL	UNIMPL	nosys
+121  AUE_NULL	UNIMPL	nosys
+122  AUE_NULL	UNIMPL	nosys
+123  AUE_NULL	UNIMPL	nosys
+124  AUE_NULL	UNIMPL	nosys
+125  AUE_NULL	UNIMPL	nosys
+126  AUE_NULL	UNIMPL	nosys
+127  AUE_NULL	UNIMPL	nosys
diff --git a/sys/compat/mach/systrace_args.c b/sys/compat/mach/systrace_args.c
new file mode 100644
index 0000000..29b05e5
--- /dev/null
+++ b/sys/compat/mach/systrace_args.c
@@ -0,0 +1,804 @@
+/*
+ * System call argument to DTrace register array converstion.
+ *
+ * DO NOT EDIT-- this file is automatically generated.
+ * $FreeBSD$
+ * This file is part of the DTrace syscall provider.
+ */
+
+static void
+systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
+{
+	int64_t *iarg  = (int64_t *) uarg;
+	switch (sysnum) {
+#if defined(_KERNEL_OPT)
+#endif
+	/* mach_reply_port */
+	case 26: {
+		*n_args = 0;
+		break;
+	}
+	/* mach_thread_self_trap */
+	case 27: {
+		*n_args = 0;
+		break;
+	}
+	/* mach_task_self_trap */
+	case 28: {
+		*n_args = 0;
+		break;
+	}
+	/* mach_host_self_trap */
+	case 29: {
+		*n_args = 0;
+		break;
+	}
+	/* mach_msg_trap */
+	case 31: {
+		struct mach_msg_trap_args *p = params;
+		uarg[0] = (intptr_t) p->msg; /* mach_msg_header_t * */
+		iarg[1] = p->option; /* mach_msg_option_t */
+		iarg[2] = p->send_size; /* mach_msg_size_t */
+		iarg[3] = p->rcv_size; /* mach_msg_size_t */
+		iarg[4] = p->rcv_name; /* mach_port_name_t */
+		iarg[5] = p->timeout; /* mach_msg_timeout_t */
+		iarg[6] = p->notify; /* mach_port_name_t */
+		*n_args = 7;
+		break;
+	}
+	/* mach_msg_overwrite_trap */
+	case 32: {
+		struct mach_msg_overwrite_trap_args *p = params;
+		uarg[0] = (intptr_t) p->msg; /* mach_msg_header_t * */
+		iarg[1] = p->option; /* mach_msg_option_t */
+		iarg[2] = p->send_size; /* mach_msg_size_t */
+		iarg[3] = p->rcv_size; /* mach_msg_size_t */
+		iarg[4] = p->rcv_name; /* mach_port_name_t */
+		iarg[5] = p->timeout; /* mach_msg_timeout_t */
+		iarg[6] = p->notify; /* mach_port_name_t */
+		uarg[7] = (intptr_t) p->rcv_msg; /* mach_msg_header_t * */
+		iarg[8] = p->scatter_list_size; /* mach_msg_size_t */
+		*n_args = 9;
+		break;
+	}
+	/* mach_semaphore_signal_trap */
+	case 33: {
+		struct mach_semaphore_signal_trap_args *p = params;
+		iarg[0] = p->signal_name; /* mach_port_name_t */
+		*n_args = 1;
+		break;
+	}
+	/* mach_semaphore_signal_all_trap */
+	case 34: {
+		struct mach_semaphore_signal_all_trap_args *p = params;
+		iarg[0] = p->signal_name; /* mach_port_name_t */
+		*n_args = 1;
+		break;
+	}
+	/* mach_semaphore_signal_thread_trap */
+	case 35: {
+		struct mach_semaphore_signal_thread_trap_args *p = params;
+		iarg[0] = p->signal_name; /* mach_port_name_t */
+		iarg[1] = p->thread; /* mach_port_name_t */
+		*n_args = 2;
+		break;
+	}
+	/* mach_semaphore_wait_trap */
+	case 36: {
+		struct mach_semaphore_wait_trap_args *p = params;
+		iarg[0] = p->wait_name; /* mach_port_name_t */
+		*n_args = 1;
+		break;
+	}
+	/* mach_semaphore_wait_signal_trap */
+	case 37: {
+		struct mach_semaphore_wait_signal_trap_args *p = params;
+		iarg[0] = p->wait_name; /* mach_port_name_t */
+		iarg[1] = p->signal_name; /* mach_port_name_t */
+		*n_args = 2;
+		break;
+	}
+	/* mach_semaphore_timedwait_trap */
+	case 38: {
+		struct mach_semaphore_timedwait_trap_args *p = params;
+		iarg[0] = p->wait_name; /* mach_port_name_t */
+		uarg[1] = p->sec; /* unsigned int */
+		iarg[2] = p->nsec; /* mach_clock_res_t */
+		*n_args = 3;
+		break;
+	}
+	/* mach_semaphore_timedwait_signal_trap */
+	case 39: {
+		struct mach_semaphore_timedwait_signal_trap_args *p = params;
+		iarg[0] = p->wait_name; /* mach_port_name_t */
+		iarg[1] = p->signal_name; /* mach_port_name_t */
+		uarg[2] = p->sec; /* unsigned int */
+		iarg[3] = p->nsec; /* mach_clock_res_t */
+		*n_args = 4;
+		break;
+	}
+	/* mach_init_process */
+	case 41: {
+		*n_args = 0;
+		break;
+	}
+	/* mach_map_fd */
+	case 43: {
+		struct mach_map_fd_args *p = params;
+		iarg[0] = p->fd; /* int */
+		iarg[1] = p->offset; /* mach_vm_offset_t */
+		uarg[2] = (intptr_t) p->va; /* mach_vm_offset_t * */
+		iarg[3] = p->findspace; /* mach_boolean_t */
+		iarg[4] = p->size; /* mach_vm_size_t */
+		*n_args = 5;
+		break;
+	}
+	/* mach_task_for_pid */
+	case 45: {
+		struct mach_task_for_pid_args *p = params;
+		iarg[0] = p->target_tport; /* mach_port_t */
+		iarg[1] = p->pid; /* int */
+		uarg[2] = (intptr_t) p->t; /* mach_port_t * */
+		*n_args = 3;
+		break;
+	}
+	/* mach_pid_for_task */
+	case 46: {
+		struct mach_pid_for_task_args *p = params;
+		iarg[0] = p->t; /* mach_port_t */
+		uarg[1] = (intptr_t) p->x; /* int * */
+		*n_args = 2;
+		break;
+	}
+	/* mach_macx_swapon */
+	case 48: {
+		struct mach_macx_swapon_args *p = params;
+		uarg[0] = (intptr_t) p->name; /* char * */
+		iarg[1] = p->flags; /* int */
+		iarg[2] = p->size; /* int */
+		iarg[3] = p->priority; /* int */
+		*n_args = 4;
+		break;
+	}
+	/* mach_macx_swapoff */
+	case 49: {
+		struct mach_macx_swapoff_args *p = params;
+		uarg[0] = (intptr_t) p->name; /* char * */
+		iarg[1] = p->flags; /* int */
+		*n_args = 2;
+		break;
+	}
+	/* mach_macx_triggers */
+	case 51: {
+		struct mach_macx_triggers_args *p = params;
+		iarg[0] = p->hi_water; /* int */
+		iarg[1] = p->low_water; /* int */
+		iarg[2] = p->flags; /* int */
+		iarg[3] = p->alert_port; /* mach_port_t */
+		*n_args = 4;
+		break;
+	}
+	/* mach_swtch_pri */
+	case 59: {
+		struct mach_swtch_pri_args *p = params;
+		iarg[0] = p->pri; /* int */
+		*n_args = 1;
+		break;
+	}
+	/* mach_swtch */
+	case 60: {
+		*n_args = 0;
+		break;
+	}
+	/* mach_syscall_thread_switch */
+	case 61: {
+		struct mach_syscall_thread_switch_args *p = params;
+		iarg[0] = p->thread_name; /* mach_port_name_t */
+		iarg[1] = p->option; /* int */
+		iarg[2] = p->option_time; /* mach_msg_timeout_t */
+		*n_args = 3;
+		break;
+	}
+	/* mach_clock_sleep_trap */
+	case 62: {
+		struct mach_clock_sleep_trap_args *p = params;
+		iarg[0] = p->clock_name; /* mach_port_name_t */
+		iarg[1] = p->sleep_type; /* mach_sleep_type_t */
+		iarg[2] = p->sleep_sec; /* int */
+		iarg[3] = p->sleep_nsec; /* int */
+		uarg[4] = (intptr_t) p->wakeup_time; /* mach_timespec_t * */
+		*n_args = 5;
+		break;
+	}
+	/* mach_timebase_info */
+	case 89: {
+		struct mach_timebase_info_args *p = params;
+		iarg[0] = p->info; /* mach_timebase_info_t */
+		*n_args = 1;
+		break;
+	}
+	/* mach_wait_until */
+	case 90: {
+		struct mach_wait_until_args *p = params;
+		uarg[0] = p->deadline; /* uint64_t */
+		*n_args = 1;
+		break;
+	}
+	/* mach_timer_create */
+	case 91: {
+		*n_args = 0;
+		break;
+	}
+	/* mach_timer_destroy */
+	case 92: {
+		struct mach_timer_destroy_args *p = params;
+		iarg[0] = p->name; /* mach_port_name_t */
+		*n_args = 1;
+		break;
+	}
+	/* mach_timer_arm */
+	case 93: {
+		struct mach_timer_arm_args *p = params;
+		iarg[0] = p->name; /* mach_port_name_t */
+		iarg[1] = p->expire_time; /* mach_absolute_time_t */
+		*n_args = 2;
+		break;
+	}
+	/* mach_timer_cancel */
+	case 94: {
+		struct mach_timer_cancel_args *p = params;
+		iarg[0] = p->name; /* mach_port_name_t */
+		uarg[1] = (intptr_t) p->result_time; /* mach_absolute_time_t * */
+		*n_args = 2;
+		break;
+	}
+	/* mach_get_time_base_info */
+	case 95: {
+		*n_args = 0;
+		break;
+	}
+	default:
+		*n_args = 0;
+		break;
+	};
+}
+static void
+systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
+{
+	const char *p = NULL;
+	switch (sysnum) {
+#if defined(_KERNEL_OPT)
+#endif
+	/* mach_reply_port */
+	case 26:
+		break;
+	/* mach_thread_self_trap */
+	case 27:
+		break;
+	/* mach_task_self_trap */
+	case 28:
+		break;
+	/* mach_host_self_trap */
+	case 29:
+		break;
+	/* mach_msg_trap */
+	case 31:
+		switch(ndx) {
+		case 0:
+			p = "mach_msg_header_t *";
+			break;
+		case 1:
+			p = "mach_msg_option_t";
+			break;
+		case 2:
+			p = "mach_msg_size_t";
+			break;
+		case 3:
+			p = "mach_msg_size_t";
+			break;
+		case 4:
+			p = "mach_port_name_t";
+			break;
+		case 5:
+			p = "mach_msg_timeout_t";
+			break;
+		case 6:
+			p = "mach_port_name_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_msg_overwrite_trap */
+	case 32:
+		switch(ndx) {
+		case 0:
+			p = "mach_msg_header_t *";
+			break;
+		case 1:
+			p = "mach_msg_option_t";
+			break;
+		case 2:
+			p = "mach_msg_size_t";
+			break;
+		case 3:
+			p = "mach_msg_size_t";
+			break;
+		case 4:
+			p = "mach_port_name_t";
+			break;
+		case 5:
+			p = "mach_msg_timeout_t";
+			break;
+		case 6:
+			p = "mach_port_name_t";
+			break;
+		case 7:
+			p = "mach_msg_header_t *";
+			break;
+		case 8:
+			p = "mach_msg_size_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_semaphore_signal_trap */
+	case 33:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_semaphore_signal_all_trap */
+	case 34:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_semaphore_signal_thread_trap */
+	case 35:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		case 1:
+			p = "mach_port_name_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_semaphore_wait_trap */
+	case 36:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_semaphore_wait_signal_trap */
+	case 37:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		case 1:
+			p = "mach_port_name_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_semaphore_timedwait_trap */
+	case 38:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		case 1:
+			p = "unsigned int";
+			break;
+		case 2:
+			p = "mach_clock_res_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_semaphore_timedwait_signal_trap */
+	case 39:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		case 1:
+			p = "mach_port_name_t";
+			break;
+		case 2:
+			p = "unsigned int";
+			break;
+		case 3:
+			p = "mach_clock_res_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_init_process */
+	case 41:
+		break;
+	/* mach_map_fd */
+	case 43:
+		switch(ndx) {
+		case 0:
+			p = "int";
+			break;
+		case 1:
+			p = "mach_vm_offset_t";
+			break;
+		case 2:
+			p = "mach_vm_offset_t *";
+			break;
+		case 3:
+			p = "mach_boolean_t";
+			break;
+		case 4:
+			p = "mach_vm_size_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_task_for_pid */
+	case 45:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_t";
+			break;
+		case 1:
+			p = "int";
+			break;
+		case 2:
+			p = "mach_port_t *";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_pid_for_task */
+	case 46:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_t";
+			break;
+		case 1:
+			p = "int *";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_macx_swapon */
+	case 48:
+		switch(ndx) {
+		case 0:
+			p = "char *";
+			break;
+		case 1:
+			p = "int";
+			break;
+		case 2:
+			p = "int";
+			break;
+		case 3:
+			p = "int";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_macx_swapoff */
+	case 49:
+		switch(ndx) {
+		case 0:
+			p = "char *";
+			break;
+		case 1:
+			p = "int";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_macx_triggers */
+	case 51:
+		switch(ndx) {
+		case 0:
+			p = "int";
+			break;
+		case 1:
+			p = "int";
+			break;
+		case 2:
+			p = "int";
+			break;
+		case 3:
+			p = "mach_port_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_swtch_pri */
+	case 59:
+		switch(ndx) {
+		case 0:
+			p = "int";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_swtch */
+	case 60:
+		break;
+	/* mach_syscall_thread_switch */
+	case 61:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		case 1:
+			p = "int";
+			break;
+		case 2:
+			p = "mach_msg_timeout_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_clock_sleep_trap */
+	case 62:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		case 1:
+			p = "mach_sleep_type_t";
+			break;
+		case 2:
+			p = "int";
+			break;
+		case 3:
+			p = "int";
+			break;
+		case 4:
+			p = "mach_timespec_t *";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_timebase_info */
+	case 89:
+		switch(ndx) {
+		case 0:
+			p = "mach_timebase_info_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_wait_until */
+	case 90:
+		switch(ndx) {
+		case 0:
+			p = "uint64_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_timer_create */
+	case 91:
+		break;
+	/* mach_timer_destroy */
+	case 92:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_timer_arm */
+	case 93:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		case 1:
+			p = "mach_absolute_time_t";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_timer_cancel */
+	case 94:
+		switch(ndx) {
+		case 0:
+			p = "mach_port_name_t";
+			break;
+		case 1:
+			p = "mach_absolute_time_t *";
+			break;
+		default:
+			break;
+		};
+		break;
+	/* mach_get_time_base_info */
+	case 95:
+		break;
+	default:
+		break;
+	};
+	if (p != NULL)
+		strlcpy(desc, p, descsz);
+}
+static void
+systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
+{
+	const char *p = NULL;
+	switch (sysnum) {
+#if defined(_KERNEL_OPT)
+#endif
+	/* mach_reply_port */
+	case 26:
+	/* mach_thread_self_trap */
+	case 27:
+	/* mach_task_self_trap */
+	case 28:
+	/* mach_host_self_trap */
+	case 29:
+	/* mach_msg_trap */
+	case 31:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_msg_overwrite_trap */
+	case 32:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_semaphore_signal_trap */
+	case 33:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_semaphore_signal_all_trap */
+	case 34:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_semaphore_signal_thread_trap */
+	case 35:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_semaphore_wait_trap */
+	case 36:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_semaphore_wait_signal_trap */
+	case 37:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_semaphore_timedwait_trap */
+	case 38:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_semaphore_timedwait_signal_trap */
+	case 39:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_init_process */
+	case 41:
+	/* mach_map_fd */
+	case 43:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_task_for_pid */
+	case 45:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_pid_for_task */
+	case 46:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_macx_swapon */
+	case 48:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_macx_swapoff */
+	case 49:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_macx_triggers */
+	case 51:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_swtch_pri */
+	case 59:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_swtch */
+	case 60:
+	/* mach_syscall_thread_switch */
+	case 61:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_clock_sleep_trap */
+	case 62:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_timebase_info */
+	case 89:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_wait_until */
+	case 90:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_timer_create */
+	case 91:
+	/* mach_timer_destroy */
+	case 92:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_timer_arm */
+	case 93:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_timer_cancel */
+	case 94:
+		if (ndx == 0 || ndx == 1)
+			p = "int";
+		break;
+	/* mach_get_time_base_info */
+	case 95:
+	default:
+		break;
+	};
+	if (p != NULL)
+		strlcpy(desc, p, descsz);
+}
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 4ada0e4..d3a4acd 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -105,7 +105,6 @@ static int	coredump(struct thread *);
 static int	killpg1(struct thread *td, int sig, int pgid, int all,
 		    ksiginfo_t *ksi);
 static int	issignal(struct thread *td);
-static int	sigprop(int sig);
 static void	tdsigwakeup(struct thread *, int, sig_t, int);
 static void	sig_suspend_threads(struct thread *, struct proc *, int);
 static int	filt_sigattach(struct knote *kn);
@@ -607,7 +606,7 @@ sigonstack(size_t sp)
 }
 
 static __inline int
-sigprop(int sig)
+__sigprop(int sig)
 {
 
 	if (sig > 0 && sig < NSIG)
@@ -616,6 +615,13 @@ sigprop(int sig)
 }
 
 int
+sigprop(int sig)
+{
+
+	return (__sigprop(sig));
+}
+
+int
 sig_ffs(sigset_t *set)
 {
 	int i;
@@ -757,7 +763,7 @@ kern_sigaction(td, sig, act, oact, flags)
 		 * have to restart the process.
 		 */
 		if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN ||
-		    (sigprop(sig) & SA_IGNORE &&
+		    (__sigprop(sig) & SA_IGNORE &&
 		     ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL)) {
 			/* never to be seen again */
 			sigqueue_delete_proc(p, sig);
@@ -925,7 +931,7 @@ siginit(p)
 	ps = p->p_sigacts;
 	mtx_lock(&ps->ps_mtx);
 	for (i = 1; i <= NSIG; i++) {
-		if (sigprop(i) & SA_IGNORE && i != SIGCONT) {
+		if (__sigprop(i) & SA_IGNORE && i != SIGCONT) {
 			SIGADDSET(ps->ps_sigignore, i);
 		}
 	}
@@ -942,7 +948,7 @@ sigdflt(struct sigacts *ps, int sig)
 
 	mtx_assert(&ps->ps_mtx, MA_OWNED);
 	SIGDELSET(ps->ps_sigcatch, sig);
-	if ((sigprop(sig) & SA_IGNORE) != 0 && sig != SIGCONT)
+	if ((__sigprop(sig) & SA_IGNORE) != 0 && sig != SIGCONT)
 		SIGADDSET(ps->ps_sigignore, sig);
 	ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL;
 	SIGDELSET(ps->ps_siginfo, sig);
@@ -970,7 +976,7 @@ execsigs(struct proc *p)
 	while (SIGNOTEMPTY(ps->ps_sigcatch)) {
 		sig = sig_ffs(&ps->ps_sigcatch);
 		sigdflt(ps, sig);
-		if ((sigprop(sig) & SA_IGNORE) != 0)
+		if ((__sigprop(sig) & SA_IGNORE) != 0)
 			sigqueue_delete_proc(p, sig);
 	}
 	/*
@@ -2100,7 +2106,7 @@ tdsendsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi)
 
 	ps = p->p_sigacts;
 	KNOTE_LOCKED(&p->p_klist, NOTE_SIGNAL | sig);
-	prop = sigprop(sig);
+	prop = __sigprop(sig);
 
 	if (td == NULL) {
 		td = sigtd(p, sig, prop);
@@ -2365,7 +2371,7 @@ tdsigwakeup(struct thread *td, int sig, sig_t action, int intrval)
 
 	wakeup_swapper = 0;
 	PROC_LOCK_ASSERT(p, MA_OWNED);
-	prop = sigprop(sig);
+	prop = __sigprop(sig);
 
 	PROC_SLOCK(p);
 	thread_lock(td);
@@ -2722,7 +2728,7 @@ issignal(struct thread *td)
 				continue;
 		}
 
-		prop = sigprop(sig);
+		prop = __sigprop(sig);
 
 		/*
 		 * Decide whether the signal should be returned.
@@ -2946,7 +2952,7 @@ sigexit(td, sig)
 	 * XXX If another thread attempts to single-thread before us
 	 *     (e.g. via fork()), we won't get a dump at all.
 	 */
-	if ((sigprop(sig) & SA_CORE) && thread_single(p, SINGLE_NO_EXIT) == 0) {
+	if ((__sigprop(sig) & SA_CORE) && (thread_single(SINGLE_NO_EXIT) == 0)) {
 		p->p_sig = sig;
 		/*
 		 * Log signals which would cause core dumps
diff --git a/sys/sys/signal.h b/sys/sys/signal.h
index 81e06a8..84e20b8 100644
--- a/sys/sys/signal.h
+++ b/sys/sys/signal.h
@@ -420,6 +420,21 @@ struct sigstack {
 #define	sigmask(m)	(1 << ((m)-1))
 #endif
 
+/*
+ * Signal properties and actions.
+ * The array below categorizes the signals and their default actions
+ * according to the following properties:
+ */
+#define	SA_KILL		0x01		/* terminates process by default */
+#define	SA_CORE		0x02		/* ditto and coredumps */
+#define	SA_STOP		0x04		/* suspend process */
+#define	SA_TTYSTOP	0x08		/* ditto, from tty */
+#define	SA_IGNORE	0x10		/* ignore by default */
+#define	SA_CONT		0x20		/* continue if suspended */
+#define	SA_CANTMASK	0x40		/* non-maskable, catchable */
+
+int sigprop(int);
+
 #if __BSD_VISIBLE
 #define	BADSIG		SIG_ERR
 #endif
-- 
1.8.4.2

